blob: 72ebc8e073374072a84accd0ef3bc260f2bd5181 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070056import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
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;
Peter Wang050bb052020-01-13 23:33:09 -0800177import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800178
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700179import java.io.FileDescriptor;
180import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800183import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800184import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800185import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100186import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700188import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191/**
192 * Implementation of the ITelephony interface.
193 */
Santos Cordon117fee72014-05-16 17:56:12 -0700194public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 private static final String LOG_TAG = "PhoneInterfaceManager";
196 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
197 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800198 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199
200 // Message codes used with mMainThreadHandler
201 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700202 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
203 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204 private static final int CMD_OPEN_CHANNEL = 9;
205 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
206 private static final int CMD_CLOSE_CHANNEL = 11;
207 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800208 private static final int CMD_NV_READ_ITEM = 13;
209 private static final int EVENT_NV_READ_ITEM_DONE = 14;
210 private static final int CMD_NV_WRITE_ITEM = 15;
211 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
212 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
213 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700214 private static final int CMD_RESET_MODEM_CONFIG = 19;
215 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800216 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
217 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
218 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
219 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800220 private static final int CMD_SEND_ENVELOPE = 25;
221 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000222 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
223 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700224 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
225 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
226 private static final int CMD_EXCHANGE_SIM_IO = 31;
227 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800228 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
229 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700230 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
231 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700232 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
233 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700234 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
235 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
236 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700238 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
239 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
240 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
241 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700242 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800243 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
244 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000245 private static final int CMD_SWITCH_SLOTS = 50;
246 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700247 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
248 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
249 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
250 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
251 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
252 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
253 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
254 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700255 private static final int CMD_GET_ALL_CELL_INFO = 60;
256 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
257 private static final int CMD_GET_CELL_LOCATION = 62;
258 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700259 private static final int CMD_MODEM_REBOOT = 64;
260 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700261 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
262 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800263 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
264 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700265 private static final int CMD_GET_MODEM_STATUS = 70;
266 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700267 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
268 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700269 private static final int CMD_ERASE_MODEM_CONFIG = 74;
270 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800272 // Parameters of select command.
273 private static final int SELECT_COMMAND = 0xA4;
274 private static final int SELECT_P1 = 0x04;
275 private static final int SELECT_P2 = 0;
276 private static final int SELECT_P3 = 0x10;
277
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 /** The singleton instance. */
279 private static PhoneInterfaceManager sInstance;
280
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800283 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700284 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private AppOpsManager mAppOps;
286 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800287 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700289 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Derek Tan97ebb422014-09-05 16:55:38 -0700291 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
292 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800294 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700295
Michelecea4cf22018-12-21 15:00:11 -0800296 // String to store multi SIM allowed
297 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
298
Derek Tan740e1672017-06-27 14:56:27 -0700299 // The AID of ISD-R.
300 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
301
yinxub1bed742017-04-17 11:45:04 -0700302 private NetworkScanRequestTracker mNetworkScanRequestTracker;
303
David Kelly5e06a7f2018-03-12 14:10:59 +0000304 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
305 private static final int MANUFACTURER_CODE_LENGTH = 8;
306
Derek Tan89e89d42014-07-08 17:00:10 -0700307 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700308 * Experiment flag to enable erase modem config on reset network, default value is false
309 */
310 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
311 "reset_network_erase_modem_config_enabled";
312
313 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class IccAPDUArgument {
317 public int channel, cla, command, p1, p2, p3;
318 public String data;
319
320 public IccAPDUArgument(int channel, int cla, int command,
321 int p1, int p2, int p3, String data) {
322 this.channel = channel;
323 this.cla = cla;
324 this.command = command;
325 this.p1 = p1;
326 this.p2 = p2;
327 this.p3 = p3;
328 this.data = data;
329 }
330 }
331
332 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class ManualNetworkSelectionArgument {
336 public OperatorInfo operatorInfo;
337 public boolean persistSelection;
338
339 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
340 this.operatorInfo = operatorInfo;
341 this.persistSelection = persistSelection;
342 }
343 }
344
345 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
347 * request after sending. The main thread will notify the request when it is complete.
348 */
349 private static final class MainThreadRequest {
350 /** The argument to use for the request */
351 public Object argument;
352 /** The result of the request that is run on the main thread */
353 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 // The subscriber id that this request applies to. Defaults to
355 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
356 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 // In cases where subId is unavailable, the caller needs to specify the phone.
359 public Phone phone;
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 public WorkSource workSource;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 public MainThreadRequest(Object argument) {
364 this.argument = argument;
365 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366
Nathan Harold92bed182018-10-12 18:16:49 -0700367 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
368 this.argument = argument;
369 if (phone != null) {
370 this.phone = phone;
371 }
372 this.workSource = workSource;
373 }
374
vagdeviaf9a5b92018-08-15 16:01:53 -0700375 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800376 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 if (subId != null) {
378 this.subId = subId;
379 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800384 private static final class IncomingThirdPartyCallArgs {
385 public final ComponentName component;
386 public final String callId;
387 public final String callerDisplayName;
388
389 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
390 String callerDisplayName) {
391 this.component = component;
392 this.callId = callId;
393 this.callerDisplayName = callerDisplayName;
394 }
395 }
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * A handler that processes messages on the main thread in the phone process. Since many
399 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
400 * inbound binder threads to the main thread in the phone process. The Binder thread
401 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
402 * on, which will be notified when the operation completes and will contain the result of the
403 * request.
404 *
405 * <p>If a MainThreadRequest object is provided in the msg.obj field,
406 * note that request.result must be set to something non-null for the calling thread to
407 * unblock.
408 */
409 private final class MainThreadHandler extends Handler {
410 @Override
411 public void handleMessage(Message msg) {
412 MainThreadRequest request;
413 Message onCompleted;
414 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800417 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 case CMD_HANDLE_USSD_REQUEST: {
421 request = (MainThreadRequest) msg.obj;
422 final Phone phone = getPhoneFromRequest(request);
423 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
424 String ussdRequest = ussdObject.first;
425 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 if (!isUssdApiAllowed(request.subId)) {
428 // Carrier does not support use of this API, return failure.
429 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
430 UssdResponse response = new UssdResponse(ussdRequest, null);
431 Bundle returnData = new Bundle();
432 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
433 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 request.result = true;
436 notifyRequester(request);
437 return;
438 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 try {
441 request.result = phone != null
442 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
443 } catch (CallStateException cse) {
444 request.result = false;
445 }
446 // Wake up the requesting thread
447 notifyRequester(request);
448 break;
pkanwar32d516d2016-10-14 19:37:38 -0700449 }
450
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 final Phone phone = getPhoneFromRequest(request);
454 request.result = phone != null ?
455 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
456 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduLogicalChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
472 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 iccArgument.channel, iccArgument.cla, iccArgument.command,
475 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 ar = (AsyncResult) msg.obj;
482 request = (MainThreadRequest) ar.userObj;
483 if (ar.exception == null && ar.result != null) {
484 request.result = ar.result;
485 } else {
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 if (ar.result == null) {
488 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800489 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800491 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 } else {
493 loge("iccTransmitApduLogicalChannel: Unknown exception");
494 }
495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
500 request = (MainThreadRequest) msg.obj;
501 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 if (uiccCard == null) {
504 loge("iccTransmitApduBasicChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 } else {
508 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
509 request);
510 uiccCard.iccTransmitApduBasicChannel(
511 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
512 iccArgument.p3, iccArgument.data, onCompleted);
513 }
514 break;
515
516 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduBasicChannel: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("iccTransmitApduBasicChannel: CommandException: " +
527 ar.exception);
528 } else {
529 loge("iccTransmitApduBasicChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
535 case CMD_EXCHANGE_SIM_IO:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccExchangeSimIO: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
545 request);
546 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
547 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
548 iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_EXCHANGE_SIM_IO_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6f, 0, (byte[])null);
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 case CMD_SEND_ENVELOPE:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("sendEnvelopeWithStatus: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
572 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
576 case EVENT_SEND_ENVELOPE_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("sendEnvelopeWithStatus: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("sendEnvelopeWithStatus: CommandException: " +
587 ar.exception);
588 } else {
589 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 case CMD_OPEN_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800601 request.result = new IccOpenLogicalChannelResponse(-1,
602 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
607 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_OPEN_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 int[] result = (int[]) ar.result;
617 int channelId = result[0];
618 byte[] selectResponse = null;
619 if (result.length > 1) {
620 selectResponse = new byte[result.length - 1];
621 for (int i = 1; i < result.length; ++i) {
622 selectResponse[i - 1] = (byte) result[i];
623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.result == null) {
629 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (ar.exception != null) {
632 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
633 }
634
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700636 if (ar.exception instanceof CommandException) {
637 CommandException.Error error =
638 ((CommandException) (ar.exception)).getCommandError();
639 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700641 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(
646 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700648 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case CMD_CLOSE_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800654 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 if (uiccCard == null) {
656 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900657 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
661 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800666 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
667 break;
668
669 case CMD_NV_READ_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 request.result = "";
683 if (ar.result == null) {
684 loge("nvReadItem: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("nvReadItem: CommandException: " +
687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800689 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Jake Hambye994d462014-02-03 13:10:13 -0800695 case CMD_NV_WRITE_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
698 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_ITEM_DONE:
704 handleNullReturnEvent(msg, "nvWriteItem");
705 break;
706
707 case CMD_NV_WRITE_CDMA_PRL:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
713 case EVENT_NV_WRITE_CDMA_PRL_DONE:
714 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
715 break;
716
chen xu6dac5ab2018-10-26 17:39:23 -0700717 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800718 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700719 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
chen xu6dac5ab2018-10-26 17:39:23 -0700723 case EVENT_RESET_MODEM_CONFIG_DONE:
724 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 case CMD_GET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result; // Integer
738 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800739 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 if (ar.result == null) {
741 loge("getPreferredNetworkType: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("getPreferredNetworkType: CommandException: " +
744 ar.exception);
745 } else {
746 loge("getPreferredNetworkType: Unknown exception");
747 }
748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case CMD_SET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
755 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
760 handleNullReturnEvent(msg, "setPreferredNetworkType");
761 break;
762
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
764 request = (MainThreadRequest)msg.obj;
765 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
769 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
770 ar = (AsyncResult)msg.obj;
771 request = (MainThreadRequest)ar.userObj;
772 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 break;
775
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800776 case CMD_SET_VOICEMAIL_NUMBER:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
779 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800780 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
781 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800782 break;
783
784 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
785 handleNullReturnEvent(msg, "setVoicemailNumber");
786 break;
787
Stuart Scott54788802015-03-30 13:18:01 -0700788 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
791 request);
792 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
797 break;
798
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 case CMD_PERFORM_NETWORK_SCAN:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
802 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
803 break;
804
805 case EVENT_PERFORM_NETWORK_SCAN_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 CellNetworkScanResult cellScanResult;
809 if (ar.exception == null && ar.result != null) {
810 cellScanResult = new CellNetworkScanResult(
811 CellNetworkScanResult.STATUS_SUCCESS,
812 (List<OperatorInfo>) ar.result);
813 } else {
814 if (ar.result == null) {
815 loge("getCellNetworkScanResults: Empty response");
816 }
817 if (ar.exception != null) {
818 loge("getCellNetworkScanResults: Exception: " + ar.exception);
819 }
820 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
823 ((CommandException) (ar.exception)).getCommandError();
824 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
826 } else if (error == CommandException.Error.GENERIC_FAILURE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
828 }
829 }
830 cellScanResult = new CellNetworkScanResult(errorCode, null);
831 }
832 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result = true;
851 } else {
852 request.result = false;
853 loge("setNetworkSelectionModeManual " + ar.exception);
854 }
855 notifyRequester(request);
856 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700857 break;
858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 case CMD_GET_MODEM_ACTIVITY_INFO:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700862 if (defaultPhone != null) {
863 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 break;
866
867 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("queryModemActivityInfo: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("queryModemActivityInfo: CommandException: " +
877 ar.exception);
878 } else {
879 loge("queryModemActivityInfo: Unknown exception");
880 }
881 }
Amit Mahajand4766222016-01-28 15:28:28 -0800882 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
883 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700884 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700887 break;
888
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 case CMD_SET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800891 CarrierRestrictionRules argument =
892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_SET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800903 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
904 if (ar.exception instanceof CommandException) {
905 loge("setAllowedCarriers: CommandException: " + ar.exception);
906 CommandException.Error error =
907 ((CommandException) (ar.exception)).getCommandError();
908 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
909 request.result =
910 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 } else {
913 loge("setAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
919 case CMD_GET_ALLOWED_CARRIERS:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
925 case EVENT_GET_ALLOWED_CARRIERS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800931 request.result = new IllegalStateException(
932 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 if (ar.result == null) {
934 loge("getAllowedCarriers: Empty response");
935 } else if (ar.exception instanceof CommandException) {
936 loge("getAllowedCarriers: CommandException: " +
937 ar.exception);
938 } else {
939 loge("getAllowedCarriers: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700943 break;
944
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = new IllegalArgumentException(
952 "Failed to retrieve Forbidden Plmns");
953 if (ar.result == null) {
954 loge("getForbiddenPlmns: Empty response");
955 } else {
956 loge("getForbiddenPlmns: Unknown exception");
957 }
958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961
962 case CMD_GET_FORBIDDEN_PLMNS:
963 request = (MainThreadRequest) msg.obj;
964 uiccCard = getUiccCardFromRequest(request);
965 if (uiccCard == null) {
966 loge("getForbiddenPlmns() UiccCard is null");
967 request.result = new IllegalArgumentException(
968 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 }
972 Integer appType = (Integer) request.argument;
973 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
974 if (uiccApp == null) {
975 loge("getForbiddenPlmns() no app with specified type -- "
976 + appType);
977 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
1001 break;
1002 case CMD_GET_NETWORK_SELECTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1005 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1006 break;
1007
1008 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1013 } else {
1014 int mode = ((int[]) ar.result)[0];
1015 if (mode == 0) {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1017 } else {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001021 notifyRequester(request);
1022 break;
1023 case CMD_GET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1026 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1027 break;
1028 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception != null) {
1032 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1033 } else {
1034 request.result = ((int[]) ar.result)[0];
1035 }
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_ROAMING_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1041 int mode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
1049 break;
1050 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1053 int subscriptionMode = (int) request.argument;
1054 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1055 break;
1056 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 request.result = ar.exception == null;
1060 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001061 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 case CMD_GET_ALL_CELL_INFO:
1063 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001065 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 case EVENT_GET_ALL_CELL_INFO_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001070 // If a timeout occurs, the response will be null
1071 request.result = (ar.exception == null && ar.result != null)
1072 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case CMD_REQUEST_CELL_INFO_UPDATE:
1078 request = (MainThreadRequest) msg.obj;
1079 request.phone.requestCellInfoUpdate(request.workSource,
1080 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1081 break;
1082 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1086 try {
1087 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001089 cb.onError(
1090 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1091 ar.exception.getClass().getName(),
1092 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001095 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else {
1097 // use the result as returned
1098 cb.onCellInfo((List<CellInfo>) ar.result);
1099 }
1100 } catch (RemoteException re) {
1101 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1102 }
1103 break;
1104 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request = (MainThreadRequest) msg.obj;
1106 WorkSource ws = (WorkSource) request.argument;
1107 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001108 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001109 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = ar.result;
1115 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001116 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001118 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001119 }
1120
1121 synchronized (request) {
1122 request.notifyAll();
1123 }
1124 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001125 case CMD_MODEM_REBOOT:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001128 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001129 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001130 case EVENT_CMD_MODEM_REBOOT_DONE:
1131 handleNullReturnEvent(msg, "rebootModem");
1132 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001133 case CMD_REQUEST_ENABLE_MODEM:
1134 request = (MainThreadRequest) msg.obj;
1135 boolean enable = (boolean) request.argument;
1136 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001138 PhoneConfigurationManager.getInstance()
1139 .enablePhone(request.phone, enable, onCompleted);
1140 break;
1141 case EVENT_ENABLE_MODEM_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001146 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 if ((boolean) request.result) {
1148 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1149 updateModemStateMetrics();
1150 } else {
1151 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1152 + ar.exception);
1153 }
1154 notifyRequester(request);
1155 break;
1156 case CMD_GET_MODEM_STATUS:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1159 PhoneConfigurationManager.getInstance()
1160 .getPhoneStatusFromModem(request.phone, onCompleted);
1161 break;
1162 case EVENT_GET_MODEM_STATUS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 int id = request.phone.getPhoneId();
1166 if (ar.exception == null && ar.result != null) {
1167 request.result = ar.result;
1168 //update the cache as modem status has changed
1169 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1170 (boolean) request.result);
1171 } else {
1172 // Return true if modem status cannot be retrieved. For most cases,
1173 // modem status is on. And for older version modems, GET_MODEM_STATUS
1174 // and disable modem are not supported. Modem is always on.
1175 // TODO: this should be fixed in R to support a third
1176 // status UNKNOWN b/131631629
1177 request.result = true;
1178 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1179 + ar.exception);
1180 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001181 notifyRequester(request);
1182 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001183 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null && ar.result != null) {
1187 request.result = ar.result;
1188 } else {
1189 request.result = -1;
1190 loge("Failed to set Forbidden Plmns");
1191 if (ar.result == null) {
1192 loge("setForbidenPlmns: Empty response");
1193 } else if (ar.exception != null) {
1194 loge("setForbiddenPlmns: Exception: " + ar.exception);
1195 request.result = -1;
1196 } else {
1197 loge("setForbiddenPlmns: Unknown exception");
1198 }
1199 }
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_FORBIDDEN_PLMNS:
1203 request = (MainThreadRequest) msg.obj;
1204 uiccCard = getUiccCardFromRequest(request);
1205 if (uiccCard == null) {
1206 loge("setForbiddenPlmns: UiccCard is null");
1207 request.result = -1;
1208 notifyRequester(request);
1209 break;
1210 }
1211 Pair<Integer, List<String>> setFplmnsArgs =
1212 (Pair<Integer, List<String>>) request.argument;
1213 appType = setFplmnsArgs.first;
1214 List<String> fplmns = setFplmnsArgs.second;
1215 uiccApp = uiccCard.getApplicationByType(appType);
1216 if (uiccApp == null) {
1217 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1218 request.result = -1;
1219 loge("Failed to get UICC App");
1220 notifyRequester(request);
1221 } else {
1222 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1223 ((SIMRecords) uiccApp.getIccRecords())
1224 .setForbiddenPlmns(onCompleted, fplmns);
1225 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001226 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001227 case CMD_ERASE_MODEM_CONFIG:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1230 defaultPhone.eraseModemConfig(onCompleted);
1231 break;
1232 case EVENT_ERASE_MODEM_CONFIG_DONE:
1233 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001234 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 default:
1236 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1237 break;
1238 }
1239 }
Jake Hambye994d462014-02-03 13:10:13 -08001240
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 private void notifyRequester(MainThreadRequest request) {
1242 synchronized (request) {
1243 request.notifyAll();
1244 }
1245 }
1246
Jake Hambye994d462014-02-03 13:10:13 -08001247 private void handleNullReturnEvent(Message msg, String command) {
1248 AsyncResult ar = (AsyncResult) msg.obj;
1249 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1250 if (ar.exception == null) {
1251 request.result = true;
1252 } else {
1253 request.result = false;
1254 if (ar.exception instanceof CommandException) {
1255 loge(command + ": CommandException: " + ar.exception);
1256 } else {
1257 loge(command + ": Unknown exception");
1258 }
1259 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
1264 /**
1265 * Posts the specified command to be executed on the main thread,
1266 * waits for the request to complete, and returns the result.
1267 * @see #sendRequestAsync
1268 */
1269 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001270 return sendRequest(
1271 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 }
1273
1274 /**
1275 * Posts the specified command to be executed on the main thread,
1276 * waits for the request to complete, and returns the result.
1277 * @see #sendRequestAsync
1278 */
1279 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1280 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001281 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
1284 /**
1285 * Posts the specified command to be executed on the main thread,
1286 * waits for the request to complete, and returns the result.
1287 * @see #sendRequestAsync
1288 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001289 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001290 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001291 }
1292
1293 /**
1294 * Posts the specified command to be executed on the main thread,
1295 * waits for the request to complete, and returns the result.
1296 * @see #sendRequestAsync
1297 */
Nathan Harold92bed182018-10-12 18:16:49 -07001298 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1299 return sendRequest(command, argument, subId, null, workSource);
1300 }
1301
1302 /**
1303 * Posts the specified command to be executed on the main thread,
1304 * waits for the request to complete, and returns the result.
1305 * @see #sendRequestAsync
1306 */
1307 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1308 return sendRequest(
1309 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1310 }
1311
1312 /**
1313 * Posts the specified command to be executed on the main thread,
1314 * waits for the request to complete, and returns the result.
1315 * @see #sendRequestAsync
1316 */
1317 private Object sendRequest(
1318 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1320 throw new RuntimeException("This method will deadlock if called from the main thread.");
1321 }
1322
Nathan Harold92bed182018-10-12 18:16:49 -07001323 MainThreadRequest request = null;
1324 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1325 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1326 } else if (phone != null) {
1327 request = new MainThreadRequest(argument, phone, workSource);
1328 } else {
1329 request = new MainThreadRequest(argument, subId, workSource);
1330 }
1331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 Message msg = mMainThreadHandler.obtainMessage(command, request);
1333 msg.sendToTarget();
1334
1335 // Wait for the request to complete
1336 synchronized (request) {
1337 while (request.result == null) {
1338 try {
1339 request.wait();
1340 } catch (InterruptedException e) {
1341 // Do nothing, go back and wait until the request is complete
1342 }
1343 }
1344 }
1345 return request.result;
1346 }
1347
1348 /**
1349 * Asynchronous ("fire and forget") version of sendRequest():
1350 * Posts the specified command to be executed on the main thread, and
1351 * returns immediately.
1352 * @see #sendRequest
1353 */
1354 private void sendRequestAsync(int command) {
1355 mMainThreadHandler.sendEmptyMessage(command);
1356 }
1357
1358 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001361 */
1362 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001363 sendRequestAsync(command, argument, null, null);
1364 }
1365
1366 /**
1367 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1368 * @see {@link #sendRequest(int,Object)}
1369 */
1370 private void sendRequestAsync(
1371 int command, Object argument, Phone phone, WorkSource workSource) {
1372 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001373 Message msg = mMainThreadHandler.obtainMessage(command, request);
1374 msg.sendToTarget();
1375 }
1376
1377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 * Initialize the singleton PhoneInterfaceManager instance.
1379 * This is only done once, at startup, from PhoneApp.onCreate().
1380 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 synchronized (PhoneInterfaceManager.class) {
1383 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001384 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 } else {
1386 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1387 }
1388 return sInstance;
1389 }
1390 }
1391
1392 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001393 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001396 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001397 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1399 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001400 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001401 mTelephonySharedPreferences =
1402 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001403 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001404 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 publish();
1407 }
1408
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001409 private Phone getDefaultPhone() {
1410 Phone thePhone = getPhone(getDefaultSubscription());
1411 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1412 }
1413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 private void publish() {
1415 if (DBG) log("publish: " + this);
1416
1417 ServiceManager.addService("phone", this);
1418 }
1419
Stuart Scott584921c2015-01-15 17:10:34 -08001420 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001421 if (request.phone != null) {
1422 return request.phone;
1423 } else {
1424 return getPhoneFromSubId(request.subId);
1425 }
1426 }
1427
1428 private Phone getPhoneFromSubId(int subId) {
1429 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1430 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001431 }
1432
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001433 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1434 Phone phone = getPhoneFromRequest(request);
1435 return phone == null ? null :
1436 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1437 }
1438
Wink Saville36469e72014-06-11 15:17:00 -07001439 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001440 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001441 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001444 private void sendEraseModemConfig(Phone phone) {
1445 if (phone != null) {
1446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1447 mApp, phone.getSubId(), "eraseModemConfig");
1448 final long identity = Binder.clearCallingIdentity();
1449 try {
1450 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1451 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1452 } finally {
1453 Binder.restoreCallingIdentity(identity);
1454 }
1455 }
1456 }
1457
Peter Wang050bb052020-01-13 23:33:09 -08001458 private boolean isImsAvailableOnDevice() {
1459 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1460 if (pm == null) {
1461 // For some reason package manger is not available.. This will fail internally anyway,
1462 // so do not throw error and allow.
1463 return true;
1464 }
1465 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1466 }
1467
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 if (DBG) log("dial: " + number);
1474 // No permission check needed here: This is just a wrapper around the
1475 // ACTION_DIAL intent, which is available to any app since it puts up
1476 // the UI before it does anything.
1477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001478 final long identity = Binder.clearCallingIdentity();
1479 try {
1480 String url = createTelUrl(number);
1481 if (url == null) {
1482 return;
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001485 // PENDING: should we just silently fail if phone is offhook or ringing?
1486 PhoneConstants.State state = mCM.getState(subId);
1487 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1488 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1489 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1490 mApp.startActivity(intent);
1491 }
1492 } finally {
1493 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 }
1495 }
1496
1497 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001498 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001499 }
1500
Wink Savilleb564aae2014-10-23 10:18:09 -07001501 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 if (DBG) log("call: " + number);
1503
1504 // This is just a wrapper around the ACTION_CALL intent, but we still
1505 // need to do a permission check since we're calling startActivity()
1506 // from the context of the phone app.
1507 enforceCallPermission();
1508
Jordan Liu1617b712019-07-10 15:06:26 -07001509 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 != AppOpsManager.MODE_ALLOWED) {
1511 return;
1512 }
1513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001514 final long identity = Binder.clearCallingIdentity();
1515 try {
1516 String url = createTelUrl(number);
1517 if (url == null) {
1518 return;
1519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 boolean isValid = false;
1522 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1523 if (slist != null) {
1524 for (SubscriptionInfo subInfoRecord : slist) {
1525 if (subInfoRecord.getSubscriptionId() == subId) {
1526 isValid = true;
1527 break;
1528 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001529 }
Wink Saville08874612014-08-31 19:19:58 -07001530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001531 if (!isValid) {
1532 return;
1533 }
Wink Saville08874612014-08-31 19:19:58 -07001534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001535 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1536 intent.putExtra(SUBSCRIPTION_KEY, subId);
1537 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1538 mApp.startActivity(intent);
1539 } finally {
1540 Binder.restoreCallingIdentity(identity);
1541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001546 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1547 }
1548
Wink Savilleb564aae2014-10-23 10:18:09 -07001549 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001550 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001551 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001556
1557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1560 checkSimPin.start();
1561 return checkSimPin.unlockSim(null, pin);
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Wink Savilleb564aae2014-10-23 10:18:09 -07001567 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001569
1570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1573 checkSimPuk.start();
1574 return checkSimPuk.unlockSim(puk, pin);
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
1577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
1580 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001581 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 * a synchronous one.
1583 */
1584 private static class UnlockSim extends Thread {
1585
1586 private final IccCard mSimCard;
1587
1588 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001589 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1590 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591
1592 // For replies from SimCard interface
1593 private Handler mHandler;
1594
1595 // For async handler to identify request type
1596 private static final int SUPPLY_PIN_COMPLETE = 100;
1597
1598 public UnlockSim(IccCard simCard) {
1599 mSimCard = simCard;
1600 }
1601
1602 @Override
1603 public void run() {
1604 Looper.prepare();
1605 synchronized (UnlockSim.this) {
1606 mHandler = new Handler() {
1607 @Override
1608 public void handleMessage(Message msg) {
1609 AsyncResult ar = (AsyncResult) msg.obj;
1610 switch (msg.what) {
1611 case SUPPLY_PIN_COMPLETE:
1612 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1613 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001614 mRetryCount = msg.arg1;
1615 if (ar.exception != null) {
1616 if (ar.exception instanceof CommandException &&
1617 ((CommandException)(ar.exception)).getCommandError()
1618 == CommandException.Error.PASSWORD_INCORRECT) {
1619 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1620 } else {
1621 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1622 }
1623 } else {
1624 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001626 mDone = true;
1627 UnlockSim.this.notifyAll();
1628 }
1629 break;
1630 }
1631 }
1632 };
1633 UnlockSim.this.notifyAll();
1634 }
1635 Looper.loop();
1636 }
1637
1638 /*
1639 * Use PIN or PUK to unlock SIM card
1640 *
1641 * If PUK is null, unlock SIM card with PIN
1642 *
1643 * If PUK is not null, unlock SIM card with PUK and set PIN code
1644 */
Wink Saville9de0f752013-10-22 19:04:03 -07001645 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646
1647 while (mHandler == null) {
1648 try {
1649 wait();
1650 } catch (InterruptedException e) {
1651 Thread.currentThread().interrupt();
1652 }
1653 }
1654 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1655
1656 if (puk == null) {
1657 mSimCard.supplyPin(pin, callback);
1658 } else {
1659 mSimCard.supplyPuk(puk, pin, callback);
1660 }
1661
1662 while (!mDone) {
1663 try {
1664 Log.d(LOG_TAG, "wait for done");
1665 wait();
1666 } catch (InterruptedException e) {
1667 // Restore the interrupted status
1668 Thread.currentThread().interrupt();
1669 }
1670 }
1671 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001672 int[] resultArray = new int[2];
1673 resultArray[0] = mResult;
1674 resultArray[1] = mRetryCount;
1675 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 }
1677 }
1678
1679 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001680 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001681
1682 }
1683
Wink Savilleb564aae2014-10-23 10:18:09 -07001684 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 // No permission check needed here: this call is harmless, and it's
1686 // needed for the ServiceState.requestStateUpdate() call (which is
1687 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001688 final long identity = Binder.clearCallingIdentity();
1689 try {
1690 final Phone phone = getPhone(subId);
1691 if (phone != null) {
1692 phone.updateServiceLocation();
1693 }
1694 } finally {
1695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001699 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001700 @Override
1701 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001702 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001703 }
1704
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001706 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1707 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1708 callingFeatureId);
1709 }
1710
1711 @Deprecated
1712 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001713 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001714 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1715 }
1716
1717 @Override
1718 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1719 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001720 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001721 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001722 return false;
1723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001724
1725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 return isRadioOnForSubscriber(subId);
1728 } finally {
1729 Binder.restoreCallingIdentity(identity);
1730 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001731 }
1732
1733 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1739 } else {
1740 return false;
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
1747 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001748 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
Wink Saville36469e72014-06-11 15:17:00 -07001750
Wink Savilleb564aae2014-10-23 10:18:09 -07001751 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
1758 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1759 }
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001762 }
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
1765 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001766 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
Wink Savilleb564aae2014-10-23 10:18:09 -07001769 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001770 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001771
1772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 final Phone phone = getPhone(subId);
1775 if (phone == null) {
1776 return false;
1777 }
1778 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1779 toggleRadioOnOffForSubscriber(subId);
1780 }
1781 return true;
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
Wink Saville36469e72014-06-11 15:17:00 -07001786
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001787 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001788 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001789 /*
1790 * If any of the Radios are available, it will need to be
1791 * shutdown. So return true if any Radio is available.
1792 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1796 Phone phone = PhoneFactory.getPhone(i);
1797 if (phone != null && phone.isRadioAvailable()) return true;
1798 }
1799 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1800 return false;
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001803 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001804 }
1805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001806 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001808 enforceModifyPermission();
1809
1810 final long identity = Binder.clearCallingIdentity();
1811 try {
1812 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1813 logv("Shutting down Phone " + i);
1814 shutdownRadioUsingPhoneId(i);
1815 }
1816 } finally {
1817 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001818 }
1819 }
1820
1821 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001822 Phone phone = PhoneFactory.getPhone(phoneId);
1823 if (phone != null && phone.isRadioAvailable()) {
1824 phone.shutdownRadio();
1825 }
1826 }
1827
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001829 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001830
1831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1834 if (defaultPhone != null) {
1835 defaultPhone.setRadioPower(turnOn);
1836 return true;
1837 } else {
1838 loge("There's no default phone.");
1839 return false;
1840 }
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001843 }
Wink Saville36469e72014-06-11 15:17:00 -07001844 }
1845
Wink Savilleb564aae2014-10-23 10:18:09 -07001846 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 final Phone phone = getPhone(subId);
1852 if (phone != null) {
1853 phone.setRadioPower(turnOn);
1854 return true;
1855 } else {
1856 return false;
1857 }
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
Wink Saville36469e72014-06-11 15:17:00 -07001863 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 public boolean enableDataConnectivity() {
1866 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867
1868 final long identity = Binder.clearCallingIdentity();
1869 try {
1870 int subId = mSubscriptionController.getDefaultDataSubId();
1871 final Phone phone = getPhone(subId);
1872 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001873 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 return true;
1875 } else {
1876 return false;
1877 }
1878 } finally {
1879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
Wink Saville36469e72014-06-11 15:17:00 -07001883 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 public boolean disableDataConnectivity() {
1886 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887
1888 final long identity = Binder.clearCallingIdentity();
1889 try {
1890 int subId = mSubscriptionController.getDefaultDataSubId();
1891 final Phone phone = getPhone(subId);
1892 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001893 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894 return true;
1895 } else {
1896 return false;
1897 }
1898 } finally {
1899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
1902
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001904 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905 final long identity = Binder.clearCallingIdentity();
1906 try {
1907 final Phone phone = getPhone(subId);
1908 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001909 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001910 } else {
1911 return false;
1912 }
1913 } finally {
1914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
1918 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
pkanwarae03a6b2016-11-06 20:37:09 -08001922 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001923 enforceCallPermission();
1924
1925 final long identity = Binder.clearCallingIdentity();
1926 try {
1927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1928 return;
1929 }
1930 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1931 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1932 } finally {
1933 Binder.restoreCallingIdentity(identity);
1934 }
pkanwar32d516d2016-10-14 19:37:38 -07001935 };
1936
Wink Savilleb564aae2014-10-23 10:18:09 -07001937 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001939
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
1942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1943 return false;
1944 }
1945 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001952 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001955 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956 final long identity = Binder.clearCallingIdentity();
1957 try {
1958 Phone phone = PhoneFactory.getPhone(slotIndex);
1959 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1960 PhoneConstantConversions.convertCallState(phone.getState());
1961 } finally {
1962 Binder.restoreCallingIdentity(identity);
1963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001967 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001968 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1969 }
1970
1971 @Override
1972 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001973 final long identity = Binder.clearCallingIdentity();
1974 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001975 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 if (phone != null) {
1977 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1978 } else {
1979 return PhoneConstantConversions.convertDataState(
1980 PhoneConstants.DataState.DISCONNECTED);
1981 }
1982 } finally {
1983 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001988 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001989 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1990 }
1991
1992 @Override
1993 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 final long identity = Binder.clearCallingIdentity();
1995 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001996 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 if (phone != null) {
1998 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1999 } else {
2000 return TelephonyManager.DATA_ACTIVITY_NONE;
2001 }
2002 } finally {
2003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 }
2006
2007 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002008 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002009 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002010 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002011
2012 LocationAccessPolicy.LocationPermissionResult locationResult =
2013 LocationAccessPolicy.checkLocationPermission(mApp,
2014 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2015 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002016 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002017 .setCallingPid(Binder.getCallingPid())
2018 .setCallingUid(Binder.getCallingUid())
2019 .setMethod("getCellLocation")
2020 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2021 .build());
2022 switch (locationResult) {
2023 case DENIED_HARD:
2024 throw new SecurityException("Not allowed to access cell location");
2025 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002026 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2027 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002031 final long identity = Binder.clearCallingIdentity();
2032 try {
2033 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002034 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002035 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 } finally {
2037 Binder.restoreCallingIdentity(identity);
2038 }
Svetoslav64fad262015-04-14 14:35:21 -07002039 }
2040
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002042 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2043 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002044 if (!TextUtils.isEmpty(callingPackage)) {
2045 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2047 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002048 return "";
2049 }
2050 }
2051
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2053 // registered cell info, so return a NULL country instead.
2054 final long identity = Binder.clearCallingIdentity();
2055 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002056 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2057 // Get default phone in this case.
2058 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2059 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002060 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002061 // Todo: fix this when we can get the actual cellular network info when the device
2062 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002063 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002064 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2065 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 return "";
2067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002068 Phone phone = PhoneFactory.getPhone(phoneId);
2069 if (phone != null) {
2070 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002071 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 if (sst != null) {
2073 LocaleTracker lt = sst.getLocaleTracker();
2074 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002075 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2076 return lt.getCurrentCountry();
2077 } else if (emergencyNumberTracker != null) {
2078 return emergencyNumberTracker.getEmergencyCountryIso();
2079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 }
2081 }
2082 }
2083 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002084 } finally {
2085 Binder.restoreCallingIdentity(identity);
2086 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002087 }
2088
2089 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002091 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002092 }
2093
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002095 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 mApp.enforceCallingOrSelfPermission(
2097 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098
2099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 final Phone phone = getPhone(subId);
2102 if (phone != null) {
2103 phone.enableLocationUpdates();
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
2110 @Override
2111 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002112 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
Sanket Padawe356d7632015-06-22 14:03:32 -07002115 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002116 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 mApp.enforceCallingOrSelfPermission(
2118 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119
2120 final long identity = Binder.clearCallingIdentity();
2121 try {
2122 final Phone phone = getPhone(subId);
2123 if (phone != null) {
2124 phone.disableLocationUpdates();
2125 }
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Nathan Harold31d7ff32018-10-15 20:20:30 -07002131 /**
2132 * Returns the target SDK version number for a given package name.
2133 *
Nathan Haroldec184742019-07-10 17:04:16 -07002134 * This call MUST be invoked before clearing the calling UID.
2135 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 * @return target SDK if the package is found or INT_MAX.
2137 */
2138 private int getTargetSdk(String packageName) {
2139 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002140 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002141 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 if (ai != null) return ai.targetSdkVersion;
2143 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002144 loge("Failed to get package info for pkg="
2145 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002146 }
2147 return Integer.MAX_VALUE;
2148 }
2149
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 @Override
2151 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002152 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2153 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002154 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002155 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2156 throw new SecurityException(
2157 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2158 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002159
Jordan Liu1617b712019-07-10 15:06:26 -07002160 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2162 return null;
2163 }
Svetoslav64fad262015-04-14 14:35:21 -07002164
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002165 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002167 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002168 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169
Nathan Haroldf180aac2018-06-01 18:43:55 -07002170 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2171 for (CellInfo ci : info) {
2172 if (ci instanceof CellInfoGsm) {
2173 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2174 } else if (ci instanceof CellInfoWcdma) {
2175 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002178 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002181 private List<CellInfo> getCachedCellInfo() {
2182 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2183 for (Phone phone : PhoneFactory.getPhones()) {
2184 List<CellInfo> info = phone.getAllCellInfo();
2185 if (info != null) cellInfos.addAll(info);
2186 }
2187 return cellInfos;
2188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189
2190 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002191 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002192 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002193 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002194
2195 LocationAccessPolicy.LocationPermissionResult locationResult =
2196 LocationAccessPolicy.checkLocationPermission(mApp,
2197 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2198 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002199 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002200 .setCallingPid(Binder.getCallingPid())
2201 .setCallingUid(Binder.getCallingUid())
2202 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002203 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002204 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2205 .build());
2206 switch (locationResult) {
2207 case DENIED_HARD:
2208 throw new SecurityException("Not allowed to access cell info");
2209 case DENIED_SOFT:
2210 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002213 final int targetSdk = getTargetSdk(callingPackage);
2214 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2215 return getCachedCellInfo();
2216 }
2217
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002218 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002219 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2223 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002224 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002225 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 if (info != null) cellInfos.addAll(info);
2227 }
2228 return cellInfos;
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232 }
2233
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002234 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002235 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2236 String callingFeatureId) {
2237 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2238 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002239 }
2240
2241 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002242 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2243 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002244 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002245 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002246 }
2247
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002248 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2249 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002250 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002252
2253 LocationAccessPolicy.LocationPermissionResult locationResult =
2254 LocationAccessPolicy.checkLocationPermission(mApp,
2255 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2256 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002257 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002258 .setCallingPid(Binder.getCallingPid())
2259 .setCallingUid(Binder.getCallingUid())
2260 .setMethod("requestCellInfoUpdate")
2261 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2262 .build());
2263 switch (locationResult) {
2264 case DENIED_HARD:
2265 throw new SecurityException("Not allowed to access cell info");
2266 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002267 try {
2268 cb.onCellInfo(new ArrayList<CellInfo>());
2269 } catch (RemoteException re) {
2270 // Drop without consequences
2271 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002272 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002273 }
2274
Nathan Harolda939a962019-05-09 10:13:47 -07002275
2276 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002277 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2278
2279 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2280 }
2281
2282 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002284 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002285 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002289 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
Shishir Agrawala9f32182016-04-12 12:00:16 -07002295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002296 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002297 Phone phone = PhoneFactory.getPhone(slotIndex);
2298 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002299 return null;
2300 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002301 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002302 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002303 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002304 return null;
2305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 return phone.getImei();
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002313 }
2314
2315 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002316 public String getTypeAllocationCodeForSlot(int slotIndex) {
2317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 String tac = null;
2319 if (phone != null) {
2320 String imei = phone.getImei();
2321 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2322 }
2323 return tac;
2324 }
2325
2326 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002327 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002328 Phone phone = PhoneFactory.getPhone(slotIndex);
2329 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002330 return null;
2331 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002332
Jeff Davidson913390f2018-02-23 17:11:49 -08002333 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002334 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002335 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002336 return null;
2337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338
2339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 return phone.getMeid();
2342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
Jack Yu2af8d712017-03-15 17:14:14 -07002345 }
2346
2347 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002348 public String getManufacturerCodeForSlot(int slotIndex) {
2349 Phone phone = PhoneFactory.getPhone(slotIndex);
2350 String manufacturerCode = null;
2351 if (phone != null) {
2352 String meid = phone.getMeid();
2353 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2354 }
2355 return manufacturerCode;
2356 }
2357
2358 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002359 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2360 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002361 Phone phone = PhoneFactory.getPhone(slotIndex);
2362 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002363 return null;
2364 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002365 int subId = phone.getSubId();
2366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002367 mApp, subId, callingPackage, callingFeatureId,
2368 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002369 return null;
2370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 return phone.getDeviceSvn();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002378 }
2379
fionaxu43304da2017-11-27 22:51:16 -08002380 @Override
2381 public int getSubscriptionCarrierId(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 ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
fionaxu43304da2017-11-27 22:51:16 -08002389 }
2390
2391 @Override
2392 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 return phone == null ? null : phone.getCarrierName();
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
2399 }
fionaxu43304da2017-11-27 22:51:16 -08002400 }
2401
calvinpanffe225e2018-11-01 19:43:06 +08002402 @Override
chen xu0026ca62019-03-06 15:28:50 -08002403 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002404 final long identity = Binder.clearCallingIdentity();
2405 try {
2406 final Phone phone = getPhone(subId);
2407 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002408 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
2412 }
2413
2414 @Override
chen xu0026ca62019-03-06 15:28:50 -08002415 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002419 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002420 } finally {
2421 Binder.restoreCallingIdentity(identity);
2422 }
2423 }
2424
chen xu651eec72018-11-11 19:03:44 -08002425 @Override
chen xu864e11c2018-12-06 22:10:03 -08002426 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2427 if (!isSubscriptionMccMnc) {
2428 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2429 }
chen xu651eec72018-11-11 19:03:44 -08002430 final Phone phone = PhoneFactory.getPhone(slotIndex);
2431 if (phone == null) {
2432 return TelephonyManager.UNKNOWN_CARRIER_ID;
2433 }
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
2439 }
2440 }
2441
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 //
2443 // Internal helper methods.
2444 //
2445
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002446 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2448 *
2449 * @throws SecurityException if the caller does not have the required permission
2450 */
2451 private void enforceModifyPermission() {
2452 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2453 }
2454
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002455 /**
2456 * Make sure the caller is system.
2457 *
2458 * @throws SecurityException if the caller is not system.
2459 */
2460 private void enforceSystemCaller() {
2461 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2462 throw new SecurityException("Caller must be system");
2463 }
2464 }
2465
Shuo Qianf2b2df42019-11-13 17:43:31 -08002466 private void enforceActiveEmergencySessionPermission() {
2467 mApp.enforceCallingOrSelfPermission(
2468 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2469 }
2470
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 /**
2472 * Make sure the caller has the CALL_PHONE permission.
2473 *
2474 * @throws SecurityException if the caller does not have the required permission
2475 */
2476 private void enforceCallPermission() {
2477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2478 }
2479
paulhu423b5f22019-08-23 19:17:33 +08002480 private void enforceSettingsPermission() {
2481 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002482 }
2483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 private String createTelUrl(String number) {
2485 if (TextUtils.isEmpty(number)) {
2486 return null;
2487 }
2488
Jake Hambye994d462014-02-03 13:10:13 -08002489 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
Ihab Awadf9e92732013-12-05 18:02:52 -08002492 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2494 }
2495
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002496 private static void logv(String msg) {
2497 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2498 }
2499
Ihab Awadf9e92732013-12-05 18:02:52 -08002500 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2502 }
2503
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002504 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002506 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002510 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 final Phone phone = PhoneFactory.getPhone(slotIndex);
2514 if (phone == null) {
2515 return PhoneConstants.PHONE_TYPE_NONE;
2516 } else {
2517 return phone.getPhoneType();
2518 }
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
2524 /**
2525 * Returns the CDMA ERI icon index to display
2526 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002527 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002528 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2529 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2530 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002531 }
2532
Sanket Padawe356d7632015-06-22 14:03:32 -07002533 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002534 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2535 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002537 mApp, subId, callingPackage, callingFeatureId,
2538 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 return -1;
2540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getCdmaEriIconIndex();
2547 } else {
2548 return -1;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 /**
2556 * Returns the CDMA ERI icon mode,
2557 * 0 - ON
2558 * 1 - FLASHING
2559 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002560 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002561 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2562 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2563 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002564 }
2565
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002567 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2568 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002570 mApp, subId, callingPackage, callingFeatureId,
2571 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002572 return -1;
2573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 return phone.getCdmaEriIconMode();
2580 } else {
2581 return -1;
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 }
2587
2588 /**
2589 * Returns the CDMA ERI text,
2590 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002591 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002592 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2593 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2594 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002595 }
2596
Sanket Padawe356d7632015-06-22 14:03:32 -07002597 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002598 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2599 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002601 mApp, subId, callingPackage, callingFeatureId,
2602 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002603 return null;
2604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 if (phone != null) {
2610 return phone.getCdmaEriText();
2611 } else {
2612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 }
2618
2619 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002620 * Returns the CDMA MDN.
2621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002630 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 return phone.getLine1Number();
2632 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002633 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 return null;
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002638 }
2639 }
2640
2641 /**
2642 * Returns the CDMA MIN.
2643 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002644 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002645 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2647 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
2652 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2653 return phone.getCdmaMin();
2654 } else {
2655 return null;
2656 }
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002659 }
2660 }
2661
Hall Liud892bec2018-11-30 14:51:45 -08002662 @Override
2663 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2664 INumberVerificationCallback callback, String callingPackage) {
2665 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2666 != PERMISSION_GRANTED) {
2667 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2668 }
2669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2670
2671 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2672 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2673 throw new SecurityException("Calling package must be configured in the device config");
2674 }
2675
2676 if (range == null) {
2677 throw new NullPointerException("Range must be non-null");
2678 }
2679
2680 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002681 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002682
2683 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2684 }
2685
Junda Liuca05d5d2014-08-14 22:36:34 -07002686 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 * Returns true if CDMA provisioning needs to run.
2688 */
2689 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 final long identity = Binder.clearCallingIdentity();
2691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002692 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
2697
2698 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002699 * Sets the voice mail number of a given subId.
2700 */
2701 @Override
2702 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002703 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2704 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2709 new Pair<String, String>(alphaTag, number), new Integer(subId));
2710 return success;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002714 }
2715
Ta-wei Yen87c49842016-05-13 21:19:52 -07002716 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002717 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002719 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2720 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002721 if (!TextUtils.equals(callingPackage, systemDialer)) {
2722 throw new SecurityException("caller must be system dialer");
2723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
2725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2728 if (phoneAccountHandle == null) {
2729 return null;
2730 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002731 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002734 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002735 }
2736
2737 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002738 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2739 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002742 mApp, subId, callingPackage, callingFeatureId,
2743 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002744 return null;
2745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002747 final long identity = Binder.clearCallingIdentity();
2748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002749 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002750 } finally {
2751 Binder.restoreCallingIdentity(identity);
2752 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002753 }
2754
2755 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002756 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2757 VisualVoicemailSmsFilterSettings settings) {
2758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002763 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002767 }
2768
2769 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002770 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2771 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772
2773 final long identity = Binder.clearCallingIdentity();
2774 try {
2775 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002776 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002780 }
2781
2782 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002783 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2784 String callingPackage, int subId) {
2785 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
2787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002790 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 } finally {
2792 Binder.restoreCallingIdentity(identity);
2793 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002794 }
2795
2796 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002797 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002798 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002803 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 } finally {
2805 Binder.restoreCallingIdentity(identity);
2806 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002807 }
2808
2809 @Override
2810 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2811 String number, int port, String text, PendingIntent sentIntent) {
2812 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002813 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002814 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002815 SmsController smsController = PhoneFactory.getSmsController();
2816 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2817 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002818 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002819
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002820 /**
fionaxu0152e512016-11-14 13:36:14 -08002821 * Sets the voice activation state of a given subId.
2822 */
2823 @Override
2824 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2826 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
2828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(subId);
2831 if (phone != null) {
2832 phone.setVoiceActivationState(activationState);
2833 } else {
2834 loge("setVoiceActivationState fails with invalid subId: " + subId);
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002838 }
2839 }
2840
2841 /**
2842 * Sets the data activation state of a given subId.
2843 */
2844 @Override
2845 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2847 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 final Phone phone = getPhone(subId);
2852 if (phone != null) {
2853 phone.setDataActivationState(activationState);
2854 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002855 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002859 }
2860 }
2861
2862 /**
2863 * Returns the voice activation state of a given subId.
2864 */
2865 @Override
2866 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868
fionaxu0152e512016-11-14 13:36:14 -08002869 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 if (phone != null) {
2873 return phone.getVoiceActivationState();
2874 } else {
2875 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2876 }
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002879 }
2880 }
2881
2882 /**
2883 * Returns the data activation state of a given subId.
2884 */
2885 @Override
2886 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002887 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888
fionaxu0152e512016-11-14 13:36:14 -08002889 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 if (phone != null) {
2893 return phone.getDataActivationState();
2894 } else {
2895 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2896 }
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002899 }
2900 }
2901
2902 /**
Wink Saville36469e72014-06-11 15:17:00 -07002903 * Returns the unread count of voicemails for a subId
2904 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002906 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2907 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002909 mApp, subId, callingPackage, callingFeatureId,
2910 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002911 return 0;
2912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 final Phone phone = getPhone(subId);
2916 if (phone != null) {
2917 return phone.getVoiceMessageCount();
2918 } else {
2919 return 0;
2920 }
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
2925
2926 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002927 * returns true, if the device is in a state where both voice and data
2928 * are supported simultaneously. This can change based on location or network condition.
2929 */
2930 @Override
2931 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 final Phone phone = getPhone(subId);
2935 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002939 }
2940
2941 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002942 * Send the dialer code if called from the current default dialer or the caller has
2943 * carrier privilege.
2944 * @param inputCode The dialer code to send
2945 */
2946 @Override
2947 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002950 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2951 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002952 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08002953 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002954 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002959 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
fionaxu235cc5e2017-03-06 22:25:57 -08002963 }
2964
Pengquan Menga1bb6272018-09-06 09:59:22 -07002965 @Override
2966 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08002967 TelephonyPermissions
2968 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
2969 mApp, subId, "getNetworkSelectionMode");
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 if (!isActiveSubscription(subId)) {
2973 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2974 }
2975 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07002978 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002979 }
2980
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002982 public boolean isInEmergencySmsMode() {
2983 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 for (Phone phone : PhoneFactory.getPhones()) {
2987 if (phone.isInEmergencySmsMode()) {
2988 return true;
2989 }
2990 }
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 return false;
2995 }
2996
shilu366312e2019-12-17 09:28:10 -08002997 /**
2998 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
2999 * @param subId The subscription to use to check the configuration.
3000 * @param c The callback that will be used to send the result.
3001 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003002 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003003 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3004 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003005 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003006 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003007
Brad Ebinger77b832e2019-10-17 17:03:22 -07003008 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3009 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3010 "IMS not available on device.");
3011 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003012 final long token = Binder.clearCallingIdentity();
3013 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003016 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003017 } catch (ImsException e) {
3018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 } finally {
3020 Binder.restoreCallingIdentity(token);
3021 }
3022 }
3023
shilu366312e2019-12-17 09:28:10 -08003024 /**
3025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3026 * @param subId The subscription to use to check the configuration.
3027 * @param c The callback that will be used to send the result.
3028 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003030 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003031 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003032 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3034 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3035 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003036 final long token = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3039 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3040 .removeRegistrationCallbackForSubscription(c, subId);
3041 } catch (ImsException e) {
3042 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3043 + "is inactive, ignoring unregister.");
3044 // If the subscription is no longer active, just return, since the callback
3045 // will already have been removed internally.
3046 } finally {
3047 Binder.restoreCallingIdentity(token);
3048 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003049 }
3050
Brad Ebinger774ba362019-10-22 17:36:18 -07003051 /**
3052 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3053 */
3054 @Override
3055 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3056 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3057 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3059 "IMS not available on device.");
3060 }
3061 final long token = Binder.clearCallingIdentity();
3062 try {
3063 Phone phone = getPhone(subId);
3064 if (phone == null) {
3065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3066 + subId + "'");
3067 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3068 }
3069 phone.getImsRegistrationState(regState -> {
3070 try {
3071 consumer.accept((regState == null)
3072 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3073 } catch (RemoteException e) {
3074 // Ignore if the remote process is no longer available to call back.
3075 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3076 }
3077 });
3078 } finally {
3079 Binder.restoreCallingIdentity(token);
3080 }
3081 }
3082
3083 /**
3084 * Get the transport type for the IMS service registration state.
3085 */
3086 @Override
3087 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003088 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003089 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3092 "IMS not available on device.");
3093 }
3094 final long token = Binder.clearCallingIdentity();
3095 try {
3096 Phone phone = getPhone(subId);
3097 if (phone == null) {
3098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3099 + subId + "'");
3100 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3101 }
3102 phone.getImsRegistrationTech(regTech -> {
3103 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3104 int regTechConverted = (regTech == null)
3105 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3106 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3107 regTechConverted);
3108 try {
3109 consumer.accept(regTechConverted);
3110 } catch (RemoteException e) {
3111 // Ignore if the remote process is no longer available to call back.
3112 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3113 }
3114 });
3115 } finally {
3116 Binder.restoreCallingIdentity(token);
3117 }
3118 }
3119
shilu366312e2019-12-17 09:28:10 -08003120 /**
3121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3122 * @param subId The subscription to use to check the configuration.
3123 * @param c The callback that will be used to send the result.
3124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003126 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3127 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003128 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003129 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003130 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3131 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3132 "IMS not available on device.");
3133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3135 final long token = Binder.clearCallingIdentity();
3136 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003137 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003139 } catch (ImsException e) {
3140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 } finally {
3142 Binder.restoreCallingIdentity(token);
3143 }
3144 }
3145
shilu366312e2019-12-17 09:28:10 -08003146 /**
3147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3148 * @param subId The subscription to use to check the configuration.
3149 * @param c The callback that will be used to send the result.
3150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003152 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003153 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003154 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003155 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3156 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3157 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003158
3159 final long token = Binder.clearCallingIdentity();
3160 try {
3161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3162 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003163 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003164 } catch (ImsException e) {
3165 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3166 + "is inactive, ignoring unregister.");
3167 // If the subscription is no longer active, just return, since the callback
3168 // will already have been removed internally.
3169 } finally {
3170 Binder.restoreCallingIdentity(token);
3171 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003172 }
3173
3174 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003175 public boolean isCapable(int subId, int capability, int regTech) {
3176 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3178 final long token = Binder.clearCallingIdentity();
3179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003182 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3184 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003185 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003186 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3187 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 } finally {
3189 Binder.restoreCallingIdentity(token);
3190 }
3191 }
3192
3193 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003194 public boolean isAvailable(int subId, int capability, int regTech) {
3195 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 final long token = Binder.clearCallingIdentity();
3197 try {
3198 Phone phone = getPhone(subId);
3199 if (phone == null) return false;
3200 return phone.isImsCapabilityAvailable(capability, regTech);
3201 } finally {
3202 Binder.restoreCallingIdentity(token);
3203 }
3204 }
3205
Brad Ebinger77b832e2019-10-17 17:03:22 -07003206 /**
3207 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3208 * subscription.
3209 * @param subId The subscription to use to check the configuration.
3210 * @param callback The callback that will be used to send the result.
3211 * @param capability The MmTelFeature capability that will be used to send the result.
3212 * @param transportType The transport type of the MmTelFeature capability.
3213 */
3214 @Override
3215 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3216 int transportType) {
3217 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3218 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3220 "IMS not available on device.");
3221 }
3222 final long token = Binder.clearCallingIdentity();
3223 try {
3224 int slotId = getSlotIndex(subId);
3225 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3226 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3227 + subId + "'");
3228 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3229 }
3230 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3231 transportType, aBoolean -> {
3232 try {
3233 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3234 } catch (RemoteException e) {
3235 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3236 + "running. Ignore");
3237 }
3238 });
3239 } finally {
3240 Binder.restoreCallingIdentity(token);
3241 }
3242 }
3243
shilu366312e2019-12-17 09:28:10 -08003244 /**
3245 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3246 * @param subId The subscription to use to check the configuration.
3247 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 @Override
3249 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003250 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3251 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3252
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3254 final long token = Binder.clearCallingIdentity();
3255 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003256 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003258 } catch (ImsException e) {
3259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 } finally {
3261 Binder.restoreCallingIdentity(token);
3262 }
3263 }
3264
3265 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003266 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003268 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (ImsException e) {
3275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
3279 }
3280
shilu366312e2019-12-17 09:28:10 -08003281 /**
3282 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3283 * @param subId The subscription to use to check the configuration.
3284 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003286 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003287 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003288 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003292 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3293 } catch (ImsException e) {
3294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
3298 }
3299
3300 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003301 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003303 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003307 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003308 } catch (ImsException e) {
3309 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
3313 }
3314
shilu366312e2019-12-17 09:28:10 -08003315 /**
3316 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3317 * @param subId The subscription to use to check the configuration.
3318 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 @Override
3320 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003321 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003326 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003327 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003328 } catch (ImsException e) {
3329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
3335 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003336 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003338 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003342 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003343 } catch (ImsException e) {
3344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
shilu366312e2019-12-17 09:28:10 -08003350 /**
3351 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3352 * @param subId The subscription to use to check the configuration.
3353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 @Override
3355 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003356 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003363 } catch (ImsException e) {
3364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
3370 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003371 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003373 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003379 } catch (ImsException e) {
3380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 @Override
3387 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3389 "setVoWiFiNonPersistent");
3390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003394 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 } 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
shilu366312e2019-12-17 09:28:10 -08003402 /**
3403 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3404 * @param subId The subscription to use to check the configuration.
3405 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 @Override
3407 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003408 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003415 } catch (ImsException e) {
3416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
3422 @Override
3423 public void setVoWiFiModeSetting(int subId, int mode) {
3424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3425 "setVoWiFiModeSetting");
3426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003429 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003431 } catch (ImsException e) {
3432 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
3436 }
3437
3438 @Override
3439 public int getVoWiFiRoamingModeSetting(int subId) {
3440 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003444 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003446 } catch (ImsException e) {
3447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
3453 @Override
3454 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3456 "setVoWiFiRoamingModeSetting");
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003462 } catch (ImsException e) {
3463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
3467 }
3468
3469 @Override
3470 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3472 "setRttCapabilityEnabled");
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3477 } catch (ImsException e) {
3478 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
3482 }
3483
shilu366312e2019-12-17 09:28:10 -08003484 /**
3485 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3486 * @param subId The subscription to use to check the configuration.
3487 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003488 @Override
3489 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003490 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003491 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003495 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003497 } catch (ImsException e) {
3498 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 } finally {
3500 Binder.restoreCallingIdentity(identity);
3501 }
3502 }
3503
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003504 @Override
3505 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3506 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003509 if (!isImsAvailableOnDevice()) {
3510 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3511 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003512 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003514 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003515 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003516 } catch (ImsException e) {
3517 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 }
3522
3523 @Override
3524 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3525 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3526 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3528 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3529 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003530 try {
3531 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003532 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003533 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003534 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003535 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3536 + "is inactive, ignoring unregister.");
3537 // If the subscription is no longer active, just return, since the callback will already
3538 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
3542 }
3543
allenwtsu99c623b2020-01-03 18:24:23 +08003544
3545 private void checkModifyPhoneStatePermission(int subId, String message) {
3546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3547 message);
3548 }
3549
3550 private boolean isImsProvisioningRequired(int subId, int capability,
3551 boolean isMmtelCapability) {
3552 Phone phone = getPhone(subId);
3553 if (phone == null) {
3554 loge("phone instance null for subid " + subId);
3555 return false;
3556 }
3557 if (isMmtelCapability) {
3558 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3559 return false;
3560 }
3561 } else {
3562 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3563 return false;
3564 }
3565 }
3566 return true;
3567 }
3568
3569 @Override
3570 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3571 boolean isProvisioned) {
3572 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3577 if (!isImsProvisioningRequired(subId, capability, false)) {
3578 return;
3579 }
3580
3581 // this capability requires provisioning, route to the correct API.
3582 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3583 switch (capability) {
3584 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3585 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3586 ims.setEabProvisioned(isProvisioned);
3587 break;
3588 default: {
3589 throw new IllegalArgumentException("Tried to set provisioning for "
3590 + "rcs capability '" + capability + "', which does not require "
3591 + "provisioning.");
3592 }
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597
3598 }
3599
3600
3601 @Override
3602 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3603 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3607 if (!isImsProvisioningRequired(subId, capability, false)) {
3608 return true;
3609 }
3610
3611 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3612 switch (capability) {
3613 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3614 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3615 return ims.isEabProvisionedOnDevice();
3616
3617 default: {
3618 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3619 + "capability '" + capability + "', which does not require "
3620 + "provisioning.");
3621 }
3622 }
3623
3624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003629 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003630 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3631 boolean isProvisioned) {
3632 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3633 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3634 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3635 }
allenwtsu99c623b2020-01-03 18:24:23 +08003636 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003640 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003641 return;
3642 }
3643
3644 // this capability requires provisioning, route to the correct API.
3645 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3646 switch (capability) {
3647 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3648 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3649 ims.setVolteProvisioned(isProvisioned);
3650 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3651 ims.setWfcProvisioned(isProvisioned);
3652 }
3653 break;
3654 }
3655 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3656 // There is currently no difference in VT provisioning type.
3657 ims.setVtProvisioned(isProvisioned);
3658 break;
3659 }
3660 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3661 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3662 // change the capability of the feature instead if needed.
3663 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3664 == isProvisioned) {
3665 // No change in provisioning.
3666 return;
3667 }
3668 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3669 try {
3670 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003671 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003672 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3673 + ", Exception" + e.getMessage());
3674 }
3675 break;
3676 }
3677 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003678 throw new IllegalArgumentException("Tried to set provisioning for "
3679 + "MmTel capability '" + capability + "', which does not require "
3680 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003681 }
3682 }
3683
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
3688
3689 @Override
3690 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3691 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3692 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3693 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3694 }
3695 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003699 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 return true;
3701 }
3702
3703 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3704 switch (capability) {
3705 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3706 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3707 return ims.isVolteProvisionedOnDevice();
3708 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3709 return ims.isWfcProvisionedOnDevice();
3710 }
3711 // This should never happen, since we are checking tech above to make sure it
3712 // is either LTE or IWLAN.
3713 throw new IllegalArgumentException("Invalid radio technology for voice "
3714 + "capability.");
3715 }
3716 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3717 // There is currently no difference in VT provisioning type.
3718 return ims.isVtProvisionedOnDevice();
3719 }
3720 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3721 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3722 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3723 }
3724 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003725 throw new IllegalArgumentException(
3726 "Tried to get provisioning for MmTel capability '" + capability
3727 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003728 }
3729 }
3730
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
3734 }
3735
3736 @Override
3737 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3738 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3739 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3740 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3741 }
3742 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3743 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3744 return (provisionedBits & capability) > 0;
3745 }
3746
3747 @Override
3748 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3749 boolean isProvisioned) {
3750 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3751 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3752 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3753 }
3754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3755 "setProvisioningStatusForCapability");
3756 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3757 // If the current provisioning status for capability already matches isProvisioned,
3758 // do nothing.
3759 if (((provisionedBits & capability) > 0) == isProvisioned) {
3760 return;
3761 }
3762 if (isProvisioned) {
3763 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3764 } else {
3765 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3766 }
3767 }
3768
3769 /**
3770 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3771 * technology. The bitfield should mirror the bitfield defined by
3772 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3773 */
3774 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3775 String key = getMmTelProvisioningKey(subId, tech);
3776 // Default is no capabilities are provisioned.
3777 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3778 }
3779
3780 /**
3781 * Sets the MmTel capability provisioning bitfield (defined by
3782 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3783 * technology specified.
3784 *
3785 * Note: This is a synchronous command and should not be called on UI thread.
3786 */
3787 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3788 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3789 String key = getMmTelProvisioningKey(subId, tech);
3790 editor.putInt(key, newField);
3791 editor.commit();
3792 }
3793
3794 private static String getMmTelProvisioningKey(int subId, int tech) {
3795 // resulting key is provision_ims_mmtel_{subId}_{tech}
3796 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3797 }
3798
3799 /**
3800 * Query CarrierConfig to see if the specified capability requires provisioning for the
3801 * carrier associated with the subscription id.
3802 */
3803 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3804 int capability) {
3805 CarrierConfigManager configManager = new CarrierConfigManager(context);
3806 PersistableBundle c = configManager.getConfigForSubId(subId);
3807 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003808 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003809 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3810 false);
3811 boolean requireVoiceVtProvisioning = c.getBoolean(
3812 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3813
3814 // First check to make sure that the capability requires provisioning.
3815 switch (capability) {
3816 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3817 // intentional fallthrough
3818 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3819 if (requireVoiceVtProvisioning) {
3820 // Voice and Video requires provisioning
3821 return true;
3822 }
3823 break;
3824 }
3825 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3826 if (requireUtProvisioning) {
3827 // UT requires provisioning
3828 return true;
3829 }
3830 break;
3831 }
3832 }
3833 return false;
3834 }
3835
allenwtsu99c623b2020-01-03 18:24:23 +08003836 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3837 int capability) {
3838 CarrierConfigManager configManager = new CarrierConfigManager(context);
3839 PersistableBundle c = configManager.getConfigForSubId(subId);
3840
3841 boolean requireRcsProvisioning = c.getBoolean(
3842 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3843
3844 // First check to make sure that the capability requires provisioning.
3845 switch (capability) {
3846 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3847 // intentional fallthrough
3848 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3849 if (requireRcsProvisioning) {
3850 // OPTION or PRESENCE requires provisioning
3851 return true;
3852 }
3853 break;
3854 }
3855 }
3856 return false;
3857 }
3858
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003859 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003860 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3862 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3863 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003864 enforceReadPrivilegedPermission("getImsProvisioningInt");
3865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003868 int slotId = getSlotIndex(subId);
3869 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3870 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3871 + subId + "' for key:" + key);
3872 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3873 }
3874 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003875 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003876 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3877 + subId + "' for key:" + key);
3878 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
3882 }
3883
3884 @Override
3885 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3887 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3888 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003889 enforceReadPrivilegedPermission("getImsProvisioningString");
3890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003893 int slotId = getSlotIndex(subId);
3894 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3895 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3896 + subId + "' for key:" + key);
3897 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3898 }
3899 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003900 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003901 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3902 + subId + "' for key:" + key);
3903 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
3906 }
3907 }
3908
3909 @Override
3910 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3912 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3913 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3915 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003919 int slotId = getSlotIndex(subId);
3920 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3921 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3922 + subId + "' for key:" + key);
3923 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3924 }
3925 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003927 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3928 + "' for key:" + key);
3929 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
3933 }
3934
3935 @Override
3936 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3938 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3939 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3941 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003945 int slotId = getSlotIndex(subId);
3946 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3947 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3948 + subId + "' for key:" + key);
3949 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3950 }
3951 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003952 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003953 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3954 + "' for key:" + key);
3955 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
3959 }
3960
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003961 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 int slotId = SubscriptionManager.getSlotIndex(subId);
3963 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003964 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3965 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 }
3967 return slotId;
3968 }
3969
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003970 private int getSlotIndex(int subId) {
3971 int slotId = SubscriptionManager.getSlotIndex(subId);
3972 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3973 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3974 }
3975 return slotId;
3976 }
3977
Wink Saville36469e72014-06-11 15:17:00 -07003978 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003979 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003980 */
3981 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003982 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3983 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003984 final int targetSdk = getTargetSdk(callingPackage);
3985 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003986 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003987 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003988 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003989 mApp, subId, callingPackage, callingFeatureId,
3990 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003991 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3992 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 final Phone phone = getPhone(subId);
3997 if (phone != null) {
3998 return phone.getServiceState().getDataNetworkType();
3999 } else {
4000 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4001 }
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004005 }
4006
4007 /**
4008 * Returns the data network type
4009 */
4010 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004011 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4012 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4013 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004014 }
4015
4016 /**
4017 * Returns the data network type for a subId
4018 */
4019 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004020 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4021 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004023 mApp, subId, callingPackage, callingFeatureId,
4024 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004025 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4026 }
4027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 final Phone phone = getPhone(subId);
4031 if (phone != null) {
4032 return phone.getServiceState().getDataNetworkType();
4033 } else {
4034 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4035 }
4036 } finally {
4037 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004039 }
4040
4041 /**
Wink Saville36469e72014-06-11 15:17:00 -07004042 * Returns the Voice network type for a subId
4043 */
4044 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004045 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4046 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004048 mApp, subId, callingPackage, callingFeatureId,
4049 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4051 }
4052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 final Phone phone = getPhone(subId);
4056 if (phone != null) {
4057 return phone.getServiceState().getVoiceNetworkType();
4058 } else {
4059 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4060 }
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004064 }
4065
4066 /**
4067 * @return true if a ICC card is present
4068 */
4069 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004070 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004071 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4072 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004073 }
4074
4075 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004076 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004077 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004078 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004079 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 final Phone phone = PhoneFactory.getPhone(slotIndex);
4083 if (phone != null) {
4084 return phone.getIccCard().hasIccCard();
4085 } else {
4086 return false;
4087 }
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004091 }
4092
4093 /**
4094 * Return if the current radio is LTE on CDMA. This
4095 * is a tri-state return value as for a period of time
4096 * the mode may be unknown.
4097 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004098 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004099 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004100 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004101 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004102 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004103 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4104 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4105 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004106 }
4107
Sanket Padawe356d7632015-06-22 14:03:32 -07004108 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004109 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4110 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004112 mApp, subId, callingPackage, callingFeatureId,
4113 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004114 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4115 }
4116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 final Phone phone = getPhone(subId);
4120 if (phone == null) {
4121 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4122 } else {
4123 return phone.getLteOnCdmaMode();
4124 }
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004127 }
Wink Saville36469e72014-06-11 15:17:00 -07004128 }
4129
Wink Saville36469e72014-06-11 15:17:00 -07004130 /**
4131 * {@hide}
4132 * Returns Default subId, 0 in the case of single standby.
4133 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004134 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004135 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004136 }
4137
Shishir Agrawala9f32182016-04-12 12:00:16 -07004138 private int getSlotForDefaultSubscription() {
4139 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4140 }
4141
Wink Savilleb564aae2014-10-23 10:18:09 -07004142 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004143 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004144 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004145
Pengquan Menge92a50d2018-09-21 15:54:48 -07004146 private boolean isActiveSubscription(int subId) {
4147 return mSubscriptionController.isActiveSubId(subId);
4148 }
4149
Ihab Awadf2177b72013-11-25 13:33:23 -08004150 /**
4151 * @see android.telephony.TelephonyManager.WifiCallingChoices
4152 */
4153 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154 final long identity = Binder.clearCallingIdentity();
4155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4158 getWhenToMakeWifiCallsDefaultPreference());
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004162 }
4163
4164 /**
4165 * @see android.telephony.TelephonyManager.WifiCallingChoices
4166 */
4167 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004171 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004176 }
4177
Sailesh Nepald1e68152013-12-12 19:08:02 -08004178 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004179 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004180 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004181 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004182
Jordan Liu4c733742019-02-28 12:03:40 -08004183 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4184 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4185 if (phoneId == -1) {
4186 throw new IllegalArgumentException("Given slot index: " + slotIndex
4187 + " does not correspond to an active phone");
4188 }
4189 return PhoneFactory.getPhone(phoneId);
4190 }
4191
Shishir Agrawal566b7612013-10-28 14:41:00 -07004192 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004193 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4194 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4196 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004198 if (DBG) {
4199 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4200 }
4201 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4202 p2);
4203 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004204
Jordan Liu4c733742019-02-28 12:03:40 -08004205
4206 @Override
4207 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4208 int slotIndex, String callingPackage, String aid, int p2) {
4209 enforceModifyPermission();
4210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4211 if (DBG) {
4212 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4213 }
4214 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4215 callingPackage, aid, p2);
4216 }
4217
4218 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4219 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 if (TextUtils.equals(ISDR_AID, aid)) {
4223 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004224 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4225 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 if (bestComponent == null
4227 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4228 loge("The calling package is not allowed to access ISD-R.");
4229 throw new SecurityException(
4230 "The calling package is not allowed to access ISD-R.");
4231 }
Derek Tan740e1672017-06-27 14:56:27 -07004232 }
Derek Tan740e1672017-06-27 14:56:27 -07004233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004235 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4236 null /* workSource */);
4237 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 return response;
4239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004242 }
4243
4244 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004245 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4247 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004248 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4249 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004251
Jordan Liu4c733742019-02-28 12:03:40 -08004252 @Override
4253 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4254 enforceModifyPermission();
4255 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4256 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4257 channel);
4258 }
4259
4260 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 if (channel < 0) {
4264 return false;
4265 }
Jordan Liu4c733742019-02-28 12:03:40 -08004266 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4267 null /* workSource */);
4268 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 return success;
4270 } finally {
4271 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004272 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004273 }
4274
4275 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004276 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004277 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4279 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004280 if (DBG) {
4281 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4282 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4283 + p3 + " data=" + data);
4284 }
4285 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4286 command, p1, p2, p3, data);
4287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004288
Jordan Liu4c733742019-02-28 12:03:40 -08004289 @Override
4290 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4291 int command, int p1, int p2, int p3, String data) {
4292 enforceModifyPermission();
4293 if (DBG) {
4294 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4295 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4296 + p3 + " data=" + data);
4297 }
4298 return iccTransmitApduLogicalChannelWithPermission(
4299 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4300 data);
4301 }
4302
4303 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4304 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 final long identity = Binder.clearCallingIdentity();
4306 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004307 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 return "";
4309 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004312 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4313 null /* workSource */);
4314 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 // Append the returned status code to the end of the response payload.
4317 String s = Integer.toHexString(
4318 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4319 if (response.payload != null) {
4320 s = IccUtils.bytesToHexString(response.payload) + s;
4321 }
4322 return s;
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004326 }
Jake Hambye994d462014-02-03 13:10:13 -08004327
Evan Charltonc66da362014-05-16 14:06:40 -07004328 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004329 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4330 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4332 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004334 if (DBG) {
4335 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4336 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4337 }
4338 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4339 cla, command, p1, p2, p3, data);
4340 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004341
Jordan Liu4c733742019-02-28 12:03:40 -08004342 @Override
4343 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4344 int command, int p1, int p2, int p3, String data) {
4345 enforceModifyPermission();
4346 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4347 if (DBG) {
4348 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4349 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4350 + " data=" + data);
4351 }
4352
4353 return iccTransmitApduBasicChannelWithPermission(
4354 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4355 p2, p3, data);
4356 }
4357
4358 // open APDU basic channel assuming the caller has sufficient permissions
4359 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4360 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 final long identity = Binder.clearCallingIdentity();
4362 try {
4363 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4364 && TextUtils.equals(ISDR_AID, data)) {
4365 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004366 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4367 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 if (bestComponent == null
4369 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4370 loge("The calling package is not allowed to select ISD-R.");
4371 throw new SecurityException(
4372 "The calling package is not allowed to select ISD-R.");
4373 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004374 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004377 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4378 null /* workSource */);
4379 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 // Append the returned status code to the end of the response payload.
4382 String s = Integer.toHexString(
4383 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4384 if (response.payload != null) {
4385 s = IccUtils.bytesToHexString(response.payload) + s;
4386 }
4387 return s;
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004390 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004391 }
4392
4393 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004394 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004395 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 if (DBG) {
4402 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4403 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4404 }
4405
4406 IccIoResult response =
4407 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4408 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4409 subId);
4410
4411 if (DBG) {
4412 log("Exchange SIM_IO [R]" + response);
4413 }
4414
4415 byte[] result = null;
4416 int length = 2;
4417 if (response.payload != null) {
4418 length = 2 + response.payload.length;
4419 result = new byte[length];
4420 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4421 } else {
4422 result = new byte[length];
4423 }
4424
4425 result[length - 1] = (byte) response.sw2;
4426 result[length - 2] = (byte) response.sw1;
4427 return result;
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004430 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004431 }
4432
Nathan Haroldb3014052017-01-25 15:57:32 -08004433 /**
4434 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4435 * on a particular subscription
4436 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004437 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4438 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004440 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004441 return null;
4442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443
4444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 if (appType != TelephonyManager.APPTYPE_USIM
4447 && appType != TelephonyManager.APPTYPE_SIM) {
4448 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4449 return null;
4450 }
4451 Object response = sendRequest(
4452 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4453 if (response instanceof String[]) {
4454 return (String[]) response;
4455 }
yincheng zhaod698b842019-09-06 17:06:54 -07004456 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004458 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004461 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004462 }
4463
yincheng zhaod698b842019-09-06 17:06:54 -07004464 /**
4465 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4466 * subscription.
4467 *
4468 * @param subId the id of the subscription.
4469 * @param appType the uicc app type, must be USIM or SIM.
4470 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4471 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004472 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004473 * @return number of fplmns that is successfully written to the SIM.
4474 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004475 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4476 String callingFeatureId) {
4477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4478 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004479 if (DBG) logv("no permissions for setForbiddenplmns");
4480 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4481 }
4482 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4483 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4484 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4485 }
4486 if (fplmns == null) {
4487 throw new IllegalArgumentException("Fplmn List provided is null");
4488 }
4489 for (String fplmn : fplmns) {
4490 if (!CellIdentity.isValidPlmn(fplmn)) {
4491 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4492 }
4493 }
4494 final long identity = Binder.clearCallingIdentity();
4495 try {
4496 Object response = sendRequest(
4497 CMD_SET_FORBIDDEN_PLMNS,
4498 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4499 subId);
4500 return (int) response;
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004506 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004507 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4509 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 final long identity = Binder.clearCallingIdentity();
4512 try {
4513 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4514 if (response.payload == null) {
4515 return "";
4516 }
Evan Charltonc66da362014-05-16 14:06:40 -07004517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 // Append the returned status code to the end of the response payload.
4519 String s = Integer.toHexString(
4520 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4521 s = IccUtils.bytesToHexString(response.payload) + s;
4522 return s;
4523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
Evan Charltonc66da362014-05-16 14:06:40 -07004526 }
4527
Jake Hambye994d462014-02-03 13:10:13 -08004528 /**
4529 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4530 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4531 *
4532 * @param itemID the ID of the item to read
4533 * @return the NV item as a String, or null on error.
4534 */
4535 @Override
4536 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004537 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4539 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540
4541 final long identity = Binder.clearCallingIdentity();
4542 try {
4543 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004544 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4546 return value;
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
Jake Hambye994d462014-02-03 13:10:13 -08004550 }
4551
4552 /**
4553 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4554 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4555 *
4556 * @param itemID the ID of the item to read
4557 * @param itemValue the value to write, as a String
4558 * @return true on success; false on any failure
4559 */
4560 @Override
4561 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004562 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4564 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4569 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004570 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4572 return success;
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
Jake Hambye994d462014-02-03 13:10:13 -08004576 }
4577
4578 /**
4579 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4580 * Used for device configuration by some CDMA operators.
4581 *
4582 * @param preferredRoamingList byte array containing the new PRL
4583 * @return true on success; false on any failure
4584 */
4585 @Override
4586 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4588 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4593 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4594 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4595 return success;
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
Jake Hambye994d462014-02-03 13:10:13 -08004599 }
4600
4601 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004602 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004603 * Used for device configuration by some CDMA operators.
4604 *
chen xu6dac5ab2018-10-26 17:39:23 -07004605 * @param slotIndex - device slot.
4606 *
Jake Hambye994d462014-02-03 13:10:13 -08004607 * @return true on success; false on any failure
4608 */
4609 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004610 public boolean resetModemConfig(int slotIndex) {
4611 Phone phone = PhoneFactory.getPhone(slotIndex);
4612 if (phone != null) {
4613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4614 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615
chen xu6dac5ab2018-10-26 17:39:23 -07004616 final long identity = Binder.clearCallingIdentity();
4617 try {
4618 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4619 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4620 return success;
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 }
chen xu6dac5ab2018-10-26 17:39:23 -07004625 return false;
4626 }
4627
4628 /**
4629 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4630 *
4631 * @param slotIndex - device slot.
4632 *
4633 * @return true on success; false on any failure
4634 */
4635 @Override
4636 public boolean rebootModem(int slotIndex) {
4637 Phone phone = PhoneFactory.getPhone(slotIndex);
4638 if (phone != null) {
4639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4640 mApp, phone.getSubId(), "rebootModem");
4641
4642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4645 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4646 return success;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
4649 }
4650 }
4651 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004652 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004653
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004654 public String[] getPcscfAddress(String apnType, String callingPackage,
4655 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004656 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4658 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004659 return new String[0];
4660 }
4661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 final long identity = Binder.clearCallingIdentity();
4663 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004664 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
Wink Saville36469e72014-06-11 15:17:00 -07004668 }
4669
Brad Ebinger51f743a2017-01-23 13:50:20 -08004670 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004671 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4672 * {@link #disableIms(int)}.
4673 * @param slotIndex device slot.
4674 */
4675 public void resetIms(int slotIndex) {
4676 enforceModifyPermission();
4677
4678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 if (mImsResolver == null) {
4681 // may happen if the does not support IMS.
4682 return;
4683 }
4684 mImsResolver.disableIms(slotIndex);
4685 mImsResolver.enableIms(slotIndex);
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
4689 }
4690
4691 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004692 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4693 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004694 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004695 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697
4698 final long identity = Binder.clearCallingIdentity();
4699 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004700 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004701 // may happen if the device does not support IMS.
4702 return;
4703 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004704 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004708 }
4709
4710 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004711 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4712 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004713 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004714 public void disableIms(int slotId) {
4715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004719 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004720 // may happen if the device does not support IMS.
4721 return;
4722 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004723 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004727 }
4728
4729 /**
4730 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4731 * feature or {@link null} if the service is not available. If the feature is available, the
4732 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4733 */
4734 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004735 IImsServiceFeatureCallback callback) {
4736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004740 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004741 // may happen if the device does not support IMS.
4742 return null;
4743 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004744 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004748 }
4749
4750 /**
4751 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4752 * feature during emergency calling or {@link null} if the service is not available. If the
4753 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4754 * listener for feature updates.
4755 */
4756 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758
4759 final long identity = Binder.clearCallingIdentity();
4760 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004761 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004762 // may happen if the device does not support IMS.
4763 return null;
4764 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004765 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004769 }
4770
Brad Ebinger5f64b052017-12-14 14:26:15 -08004771 /**
4772 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004773 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004774 */
4775 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777
4778 final long identity = Binder.clearCallingIdentity();
4779 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004780 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004781 // may happen if the device does not support IMS.
4782 return null;
4783 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004784 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004788 }
4789
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004790 /**
4791 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004792 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004793 */
4794 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796
4797 final long identity = Binder.clearCallingIdentity();
4798 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004799 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004800 // may happen if the device does not support IMS.
4801 return null;
4802 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004803 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 } finally {
4805 Binder.restoreCallingIdentity(identity);
4806 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004807 }
4808
Brad Ebinger884c07b2018-02-15 16:17:40 -08004809 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004810 * Sets the ImsService Package Name that Telephony will bind to.
4811 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004812 * @param slotIndex the slot ID that the ImsService should bind for.
4813 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004814 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004815 * @param featureTypes An integer array of feature types associated with a packageName.
4816 * @param packageName The name of the package that the current configuration will be replaced
4817 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004818 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004819 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004820 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4821 int[] featureTypes, String packageName) {
4822 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4825 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004826 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 final long identity = Binder.clearCallingIdentity();
4829 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004830 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004831 // may happen if the device does not support IMS.
4832 return false;
4833 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004834 Map<Integer, String> featureConfig = new HashMap<>();
4835 for (int featureType : featureTypes) {
4836 featureConfig.put(featureType, packageName);
4837 }
4838 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4839 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004840 } finally {
4841 Binder.restoreCallingIdentity(identity);
4842 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004843 }
4844
4845 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004846 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004847 *
4848 * @param slotId The slot that the ImsService is associated with.
4849 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4850 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004851 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004852 * @return the package name of the ImsService configuration.
4853 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004854 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4855 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004856 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004857 TelephonyPermissions
4858 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4859 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4860 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 final long identity = Binder.clearCallingIdentity();
4863 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004864 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004865 // may happen if the device does not support IMS.
4866 return "";
4867 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004868 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004869 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4870 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004874 }
4875
Brad Ebinger77b832e2019-10-17 17:03:22 -07004876 /**
4877 * Get the MmTelFeature state associated with the requested subscription id.
4878 * @param subId The subscription that the MmTelFeature is associated with.
4879 * @param callback A callback with an integer containing the
4880 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4881 */
4882 @Override
4883 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4884 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4885 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4886 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4887 "IMS not available on device.");
4888 }
4889 final long token = Binder.clearCallingIdentity();
4890 try {
4891 int slotId = getSlotIndex(subId);
4892 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4893 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4894 + subId + "'");
4895 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4896 }
4897 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4898 try {
4899 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4900 } catch (RemoteException e) {
4901 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4902 + "Ignore");
4903 }
4904 });
4905 } finally {
4906 Binder.restoreCallingIdentity(token);
4907 }
4908 }
4909
Wink Saville36469e72014-06-11 15:17:00 -07004910 public void setImsRegistrationState(boolean registered) {
4911 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912
4913 final long identity = Binder.clearCallingIdentity();
4914 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004915 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
Wink Saville36469e72014-06-11 15:17:00 -07004919 }
4920
4921 /**
Stuart Scott54788802015-03-30 13:18:01 -07004922 * Set the network selection mode to automatic.
4923 *
4924 */
4925 @Override
4926 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4928 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929
4930 final long identity = Binder.clearCallingIdentity();
4931 try {
shilufc958392020-01-20 11:36:01 -08004932 if (!isActiveSubscription(subId)) {
4933 return;
4934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4936 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Stuart Scott54788802015-03-30 13:18:01 -07004940 }
4941
Pengquan Mengea84e042018-09-20 14:57:26 -07004942 /**
4943 * Ask the radio to connect to the input network and change selection mode to manual.
4944 *
4945 * @param subId the id of the subscription.
4946 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4947 * the operator to attach to.
4948 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4949 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4950 * normal network selection next time.
4951 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004952 */
4953 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004954 public boolean setNetworkSelectionModeManual(
4955 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4957 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004958
4959 if (!isActiveSubscription(subId)) {
4960 return false;
4961 }
4962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 final long identity = Binder.clearCallingIdentity();
4964 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004965 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004967 if (DBG) {
4968 log("setNetworkSelectionModeManual: subId: " + subId
4969 + " operator: " + operatorInfo);
4970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004975 }
4976
4977 /**
4978 * Scans for available networks.
4979 */
4980 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004981 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4982 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004985 LocationAccessPolicy.LocationPermissionResult locationResult =
4986 LocationAccessPolicy.checkLocationPermission(mApp,
4987 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4988 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004989 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004990 .setCallingPid(Binder.getCallingPid())
4991 .setCallingUid(Binder.getCallingUid())
4992 .setMethod("getCellNetworkScanResults")
4993 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4994 .build());
4995 switch (locationResult) {
4996 case DENIED_HARD:
4997 throw new SecurityException("Not allowed to access scan results -- location");
4998 case DENIED_SOFT:
4999 return null;
5000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
Pengquan Menga1bb6272018-09-06 09:59:22 -07005002 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 try {
5004 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005005 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005010 }
5011
5012 /**
yinxub1bed742017-04-17 11:45:04 -07005013 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005014 *
yinxub1bed742017-04-17 11:45:04 -07005015 * @param subId id of the subscription
5016 * @param request contains the radio access networks with bands/channels to scan
5017 * @param messenger callback messenger for scan results or errors
5018 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005019 * @return the id of the requested scan which can be used to stop the scan.
5020 */
5021 @Override
5022 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005023 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5025 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005026 LocationAccessPolicy.LocationPermissionResult locationResult =
5027 LocationAccessPolicy.checkLocationPermission(mApp,
5028 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5029 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005030 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005031 .setCallingPid(Binder.getCallingPid())
5032 .setCallingUid(Binder.getCallingUid())
5033 .setMethod("requestNetworkScan")
5034 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5035 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005036 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005037 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005038 if (e != null) {
5039 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5040 throw e;
5041 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005042 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005043 return TelephonyScanManager.INVALID_SCAN_ID;
5044 }
5045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 }
Hall Liu912dfd32019-04-25 14:02:26 -07005047 int callingUid = Binder.getCallingUid();
5048 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 return mNetworkScanRequestTracker.startNetworkScan(
5052 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005053 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
yinxu504e1392017-04-12 16:03:22 -07005057 }
5058
Hall Liub2ac8ef2019-02-28 15:56:23 -08005059 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005060 NetworkScanRequest request, int subId) {
5061 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5062 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5063 boolean hasNetworkScanPermission =
5064 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5065 == PERMISSION_GRANTED;
5066
5067 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5068 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5069 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005070 }
5071
5072 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5073 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005074 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5075 return new SecurityException("Specific channels must not be"
5076 + " scanned without location access.");
5077 }
5078 }
5079 }
5080
Hall Liub2ac8ef2019-02-28 15:56:23 -08005081 return null;
5082 }
5083
yinxu504e1392017-04-12 16:03:22 -07005084 /**
5085 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005086 *
5087 * @param subId id of the subscription
5088 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005089 */
5090 @Override
5091 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5093 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094
Hall Liu912dfd32019-04-25 14:02:26 -07005095 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005098 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
yinxu504e1392017-04-12 16:03:22 -07005102 }
5103
5104 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005105 * Get the calculated preferred network type.
5106 * Used for debugging incorrect network type.
5107 *
5108 * @return the preferred network type, defined in RILConstants.java.
5109 */
5110 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005111 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005112 final Phone defaultPhone = getDefaultPhone();
5113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005114 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005115 return RILConstants.PREFERRED_NETWORK_MODE;
5116 }
5117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005121 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
Junda Liu84d15a22014-07-02 11:21:04 -07005125 }
5126
5127 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005128 * Get the preferred network type.
5129 * Used for device configuration by some CDMA operators.
5130 *
5131 * @return the preferred network type, defined in RILConstants.java.
5132 */
5133 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005134 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005135 TelephonyPermissions
5136 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5137 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138
5139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 if (DBG) log("getPreferredNetworkType");
5142 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5143 int networkType = (result != null ? result[0] : -1);
5144 if (DBG) log("getPreferredNetworkType: " + networkType);
5145 return networkType;
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005149 }
5150
5151 /**
5152 * Set the preferred network type.
5153 * Used for device configuration by some CDMA operators.
5154 *
5155 * @param networkType the preferred network type, defined in RILConstants.java.
5156 * @return true on success; false on any failure.
5157 */
5158 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005159 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5161 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005165 Settings.Global.putInt(mApp.getContentResolver(),
5166 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5167 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 } finally {
5169 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005170 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005171 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005172
5173 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005174 * Get the allowed network types that store in the telephony provider.
5175 *
5176 * @param subId the id of the subscription.
5177 * @return allowedNetworkTypes the allowed network types.
5178 */
5179 @Override
5180 public long getAllowedNetworkTypes(int subId) {
5181 TelephonyPermissions
5182 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5183 mApp, subId, "getAllowedNetworkTypes");
5184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 return SubscriptionManager.getLongSubscriptionProperty(
5188 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
5192 }
5193
5194 /**
5195 * Set the allowed network types.
5196 *
5197 * @param subId the id of the subscription.
5198 * @param allowedNetworkTypes the allowed network types.
5199 * @return true on success; false on any failure.
5200 */
5201 @Override
5202 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5204 mApp, subId, "setAllowedNetworkTypes");
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 SubscriptionManager.setSubscriptionProperty(subId,
5208 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5209 String.valueOf(allowedNetworkTypes));
5210 return setPreferredNetworkTypesInternal(subId);
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
5214 }
5215
5216 private boolean setPreferredNetworkTypesInternal(int subId) {
5217 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5218 Settings.Global.getInt(mApp.getContentResolver(),
5219 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5220 RILConstants.PREFERRED_NETWORK_MODE));
5221 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5222 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5223 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5224 (int) (networkTypeBitMask & allowedNetworkTypes));
5225
5226 if (DBG) {
5227 log("setPreferredNetworkTypesInternal: subId " + subId
5228 + " networkTypes " + networkTypeBitMask
5229 + " allowedNetworkTypes " + allowedNetworkTypes
5230 + " networkMode " + networkMode);
5231 }
5232
5233 Boolean success = (Boolean) sendRequest(
5234 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5235 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5236 return success;
5237 }
5238
5239 /**
Miaoa84611c2019-03-15 09:21:10 +08005240 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005241 *
Miaoa84611c2019-03-15 09:21:10 +08005242 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005243 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005244 * @hide
5245 */
5246 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005247 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 try {
Miaoa84611c2019-03-15 09:21:10 +08005252 if (phone != null) {
5253 return phone.hasMatchedTetherApnSetting();
5254 } else {
5255 return false;
5256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 } finally {
5258 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005259 }
Junda Liu475951f2014-11-07 16:45:03 -08005260 }
5261
5262 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005263 * Set mobile data enabled
5264 * Used by the user through settings etc to turn on/off mobile data
5265 *
5266 * @param enable {@code true} turn turn data on, else {@code false}
5267 */
5268 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005269 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5271 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272
5273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 int phoneId = mSubscriptionController.getPhoneId(subId);
5276 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5277 Phone phone = PhoneFactory.getPhone(phoneId);
5278 if (phone != null) {
5279 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005280 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005282 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 }
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005286 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005287 }
5288
5289 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005290 * Enable or disable always reporting signal strength changes from radio.
5291 *
5292 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5293 */
5294 @Override
5295 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5296 enforceModifyPermission();
5297 enforceSystemCaller();
5298
5299 final long identity = Binder.clearCallingIdentity();
5300 final Phone phone = getPhone(subId);
5301 try {
5302 if (phone != null) {
5303 if (DBG) {
5304 log("setAlwaysReportSignalStrength: subId=" + subId
5305 + " isEnable=" + isEnable);
5306 }
5307 phone.setAlwaysReportSignalStrength(isEnable);
5308 } else {
5309 loge("setAlwaysReportSignalStrength: no phone found for subId="
5310 + subId);
5311 }
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
5315 }
5316
5317 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005318 * Get the user enabled state of Mobile Data.
5319 *
5320 * TODO: remove and use isUserDataEnabled.
5321 * This can't be removed now because some vendor codes
5322 * calls through ITelephony directly while they should
5323 * use TelephonyManager.
5324 *
5325 * @return true on enabled
5326 */
5327 @Override
5328 public boolean getDataEnabled(int subId) {
5329 return isUserDataEnabled(subId);
5330 }
5331
5332 /**
5333 * Get whether mobile data is enabled per user setting.
5334 *
5335 * There are other factors deciding whether mobile data is actually enabled, but they are
5336 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005337 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005338 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005339 *
5340 * @return {@code true} if data is enabled else {@code false}
5341 */
5342 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005343 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005344 try {
5345 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5346 null);
5347 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5349 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 int phoneId = mSubscriptionController.getPhoneId(subId);
5355 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5356 Phone phone = PhoneFactory.getPhone(phoneId);
5357 if (phone != null) {
5358 boolean retVal = phone.isUserDataEnabled();
5359 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5360 return retVal;
5361 } else {
5362 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5363 return false;
5364 }
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005367 }
5368 }
5369
5370 /**
5371 * Get whether mobile data is enabled.
5372 *
5373 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5374 * whether mobile data is actually enabled.
5375 *
5376 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5377 *
5378 * @return {@code true} if data is enabled else {@code false}
5379 */
5380 @Override
5381 public boolean isDataEnabled(int subId) {
5382 try {
5383 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5384 null);
5385 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5387 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389
5390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 int phoneId = mSubscriptionController.getPhoneId(subId);
5393 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5394 Phone phone = PhoneFactory.getPhone(phoneId);
5395 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005396 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5398 return retVal;
5399 } else {
5400 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5401 return false;
5402 }
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005405 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005406 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005407
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005408 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5409 Phone phone) {
5410 //load access rules from carrier configs, and check those as well: b/139133814
5411 SubscriptionController subController = SubscriptionController.getInstance();
5412 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5413 || subController == null) return privilegeFromSim;
5414
5415 int uid = Binder.getCallingUid();
5416 PackageManager pkgMgr = phone.getContext().getPackageManager();
5417 String[] packages = pkgMgr.getPackagesForUid(uid);
5418
5419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5422 SubscriptionManager subManager = (SubscriptionManager)
5423 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5424 for (String pkg : packages) {
5425 if (subManager.canManageSubscription(subInfo, pkg)) {
5426 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5427 }
5428 }
5429 return privilegeFromSim;
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
5432 }
5433 }
5434
5435 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5436 String pkgName) {
5437 //load access rules from carrier configs, and check those as well: b/139133814
5438 SubscriptionController subController = SubscriptionController.getInstance();
5439 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5440 || subController == null) return privilegeFromSim;
5441
5442 final long identity = Binder.clearCallingIdentity();
5443 try {
5444 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5445 SubscriptionManager subManager = (SubscriptionManager)
5446 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5447 return subManager.canManageSubscription(subInfo, pkgName)
5448 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005454 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005455 public int getCarrierPrivilegeStatus(int subId) {
5456 final Phone phone = getPhone(subId);
5457 if (phone == null) {
5458 loge("getCarrierPrivilegeStatus: Invalid subId");
5459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5460 }
5461 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005462 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005463 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005464 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5465 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005466
5467 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5468 card.getCarrierPrivilegeStatusForCurrentTransaction(
5469 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005470 }
Junda Liu29340342014-07-10 15:23:27 -07005471
5472 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005473 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005474 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005475 final Phone phone = getPhone(subId);
5476 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005477 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005478 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5479 }
5480 UiccProfile profile =
5481 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5482 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005483 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005484 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5485 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005486 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005487 profile.getCarrierPrivilegeStatusForUid(
5488 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005489 }
5490
5491 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005492 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5493 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005494 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005495 }
5496
5497 int phoneId = SubscriptionManager.getPhoneId(subId);
5498 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005499 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005500 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005501 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5502 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005503 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5504 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5505 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005506 }
5507
5508 @Override
5509 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005510 if (TextUtils.isEmpty(pkgName))
5511 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005512 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5513 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5514 UiccCard card = UiccController.getInstance().getUiccCard(i);
5515 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005516 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005517 continue;
5518 }
5519
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005520 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5521 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5522 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005523 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5524 break;
5525 }
5526 }
5527
5528 return result;
Junda Liu29340342014-07-10 15:23:27 -07005529 }
Derek Tan89e89d42014-07-08 17:00:10 -07005530
5531 @Override
Junda Liue64de782015-04-16 17:19:16 -07005532 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5533 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5534 loge("phoneId " + phoneId + " is not valid.");
5535 return null;
5536 }
5537 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005538 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005539 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005540 return null ;
5541 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005542 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005543 }
5544
Amith Yamasani6e118872016-02-19 12:53:51 -08005545 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005546 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005547 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005548 List<String> privilegedPackages = new ArrayList<>();
5549 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005550 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5551 // has UICC in that slot.
5552 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005553 if (card.hasCarrierPrivilegeRules()) {
5554 if (packages == null) {
5555 // Only check packages in user 0 for now
5556 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005557 PackageManager.MATCH_DISABLED_COMPONENTS
5558 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005559 | PackageManager.GET_SIGNING_CERTIFICATES,
5560 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005561 }
5562 for (int p = packages.size() - 1; p >= 0; p--) {
5563 PackageInfo pkgInfo = packages.get(p);
5564 if (pkgInfo != null && pkgInfo.packageName != null
5565 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005566 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005567 privilegedPackages.add(pkgInfo.packageName);
5568 }
5569 }
5570 }
5571 }
5572 return privilegedPackages;
5573 }
5574
chen xuf7e9fe82019-05-09 19:31:02 -07005575 @Override
5576 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005577 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5578
5579 final long identity = Binder.clearCallingIdentity();
5580
chen xuf7e9fe82019-05-09 19:31:02 -07005581 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005582 try {
5583 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5584 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5585 }
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005588 }
5589 return privilegedPackages;
5590 }
5591
Wink Savilleb564aae2014-10-23 10:18:09 -07005592 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005593 final Phone phone = getPhone(subId);
5594 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005595 if (card == null) {
5596 loge("getIccId: No UICC");
5597 return null;
5598 }
5599 String iccId = card.getIccId();
5600 if (TextUtils.isEmpty(iccId)) {
5601 loge("getIccId: ICC ID is null or empty.");
5602 return null;
5603 }
5604 return iccId;
5605 }
5606
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005607 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005608 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5609 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005610 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005611 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 final String iccId = getIccId(subId);
5616 final Phone phone = getPhone(subId);
5617 if (phone == null) {
5618 return false;
5619 }
5620 final String subscriberId = phone.getSubscriberId();
5621
5622 if (DBG_MERGE) {
5623 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5624 + subscriberId + " to " + number);
5625 }
5626
5627 if (TextUtils.isEmpty(iccId)) {
5628 return false;
5629 }
5630
5631 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5632
5633 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5634 if (alphaTag == null) {
5635 editor.remove(alphaTagPrefKey);
5636 } else {
5637 editor.putString(alphaTagPrefKey, alphaTag);
5638 }
5639
5640 // Record both the line number and IMSI for this ICCID, since we need to
5641 // track all merged IMSIs based on line number
5642 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5643 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5644 if (number == null) {
5645 editor.remove(numberPrefKey);
5646 editor.remove(subscriberPrefKey);
5647 } else {
5648 editor.putString(numberPrefKey, number);
5649 editor.putString(subscriberPrefKey, subscriberId);
5650 }
5651
5652 editor.commit();
5653 return true;
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005656 }
Derek Tan7226c842014-07-02 17:42:23 -07005657 }
5658
5659 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005660 public String getLine1NumberForDisplay(int subId, String callingPackage,
5661 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005662 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005664 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005665 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005666 return null;
5667 }
Derek Tan97ebb422014-09-05 16:55:38 -07005668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 String iccId = getIccId(subId);
5672 if (iccId != null) {
5673 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5674 if (DBG_MERGE) {
5675 log("getLine1NumberForDisplay returning "
5676 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5677 }
5678 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5681 return null;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005684 }
Derek Tan7226c842014-07-02 17:42:23 -07005685 }
5686
5687 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005688 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5689 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005691 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005692 return null;
5693 }
Derek Tan97ebb422014-09-05 16:55:38 -07005694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 String iccId = getIccId(subId);
5698 if (iccId != null) {
5699 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5700 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5701 }
5702 return null;
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005705 }
Derek Tan7226c842014-07-02 17:42:23 -07005706 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005707
5708 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005709 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5710 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005711 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5712 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005714 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005715 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005716 return null;
5717 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005718
Jordan Liub49b04b2019-05-06 14:45:15 -07005719 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5720 // the process, where TelephonyManager was instantiated.
5721 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005722 final long identity = Binder.clearCallingIdentity();
5723 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final TelephonyManager tele = TelephonyManager.from(context);
5726 final SubscriptionManager sub = SubscriptionManager.from(context);
5727
5728 // Figure out what subscribers are currently active
5729 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730
Jordan Liub49b04b2019-05-06 14:45:15 -07005731 // Only consider subs which match the current subId
5732 // This logic can be simplified. See b/131189269 for progress.
5733 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005734 activeSubscriberIds.add(tele.getSubscriberId(subId));
5735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736
5737 // First pass, find a number override for an active subscriber
5738 String mergeNumber = null;
5739 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5740 for (String key : prefs.keySet()) {
5741 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5742 final String subscriberId = (String) prefs.get(key);
5743 if (activeSubscriberIds.contains(subscriberId)) {
5744 final String iccId = key.substring(
5745 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5746 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5747 mergeNumber = (String) prefs.get(numberKey);
5748 if (DBG_MERGE) {
5749 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5750 + " for active subscriber " + subscriberId);
5751 }
5752 if (!TextUtils.isEmpty(mergeNumber)) {
5753 break;
5754 }
5755 }
5756 }
5757 }
5758
5759 // Shortcut when no active merged subscribers
5760 if (TextUtils.isEmpty(mergeNumber)) {
5761 return null;
5762 }
5763
5764 // Second pass, find all subscribers under that line override
5765 final ArraySet<String> result = new ArraySet<>();
5766 for (String key : prefs.keySet()) {
5767 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5768 final String number = (String) prefs.get(key);
5769 if (mergeNumber.equals(number)) {
5770 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5771 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5772 final String subscriberId = (String) prefs.get(subscriberKey);
5773 if (!TextUtils.isEmpty(subscriberId)) {
5774 result.add(subscriberId);
5775 }
5776 }
5777 }
5778 }
5779
5780 final String[] resultArray = result.toArray(new String[result.size()]);
5781 Arrays.sort(resultArray);
5782 if (DBG_MERGE) {
5783 Slog.d(LOG_TAG,
5784 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5785 }
5786 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005789 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005790 }
5791
5792 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005793 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5794 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5795
5796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 final TelephonyManager telephonyManager = mApp.getSystemService(
5799 TelephonyManager.class);
5800 String subscriberId = telephonyManager.getSubscriberId(subId);
5801 if (subscriberId == null) {
5802 if (DBG) {
5803 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5804 + subId);
5805 }
5806 return null;
5807 }
5808
5809 final SubscriptionInfo info = SubscriptionController.getInstance()
5810 .getSubscriptionInfo(subId);
5811 final ParcelUuid groupUuid = info.getGroupUuid();
5812 // If it doesn't belong to any group, return just subscriberId of itself.
5813 if (groupUuid == null) {
5814 return new String[]{subscriberId};
5815 }
5816
5817 // Get all subscriberIds from the group.
5818 final List<String> mergedSubscriberIds = new ArrayList<>();
5819 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005820 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5821 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005822 for (SubscriptionInfo subInfo : groupInfos) {
5823 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5824 if (subscriberId != null) {
5825 mergedSubscriberIds.add(subscriberId);
5826 }
5827 }
5828
5829 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832
5833 }
5834 }
5835
5836 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005837 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005838 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005839 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 final Phone phone = getPhone(subId);
5844 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005848 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005849
5850 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005851 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005852 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5853 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005854 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5855 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 final Phone phone = getPhone(subId);
5860 if (phone == null) {
5861 return false;
5862 }
5863 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5864 cdmaNonRoamingList);
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005867 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005868 }
5869
5870 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005871 @Deprecated
5872 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5873 enforceModifyPermission();
5874
5875 int returnValue = 0;
5876 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005877 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005878 if(result.exception == null) {
5879 if (result.result != null) {
5880 byte[] responseData = (byte[])(result.result);
5881 if(responseData.length > oemResp.length) {
5882 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5883 responseData.length + "bytes. Buffer Size is " +
5884 oemResp.length + "bytes.");
5885 }
5886 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5887 returnValue = responseData.length;
5888 }
5889 } else {
5890 CommandException ex = (CommandException) result.exception;
5891 returnValue = ex.getCommandError().ordinal();
5892 if(returnValue > 0) returnValue *= -1;
5893 }
5894 } catch (RuntimeException e) {
5895 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5896 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5897 if(returnValue > 0) returnValue *= -1;
5898 }
5899
5900 return returnValue;
5901 }
5902
5903 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005904 public void setRadioCapability(RadioAccessFamily[] rafs) {
5905 try {
5906 ProxyController.getInstance().setRadioCapability(rafs);
5907 } catch (RuntimeException e) {
5908 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5909 }
5910 }
5911
5912 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005913 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005914 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005915 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005916 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005917 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 final long identity = Binder.clearCallingIdentity();
5920 try {
chen xub97461a2018-10-26 14:17:57 -07005921 TelephonyPermissions
5922 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5923 mApp, phone.getSubId(), "getRadioAccessFamily");
5924 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
chen xub97461a2018-10-26 14:17:57 -07005928 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005929 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005930
5931 @Override
5932 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005933 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935
5936 final long identity = Binder.clearCallingIdentity();
5937 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938 ImsManager.getInstance(defaultPhone.getContext(),
5939 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005943 }
5944
5945 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005946 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005947 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5949 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005950 return false;
5951 }
Svet Ganovb320e182015-04-16 12:30:10 -07005952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 // Check the user preference and the system-level IMS setting. Even if the user has
5956 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5957 // In the long run, we may instead need to check if there exists a connection service
5958 // which can support video calling.
5959 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 return imsManager.isVtEnabledByPlatform()
5962 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5963 && imsManager.isVtEnabledByUser();
5964 } finally {
5965 Binder.restoreCallingIdentity(identity);
5966 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005967 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005968
Andrew Leea1239f22015-03-02 17:44:07 -08005969 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005970 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5971 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005973 mApp, subId, callingPackage, callingFeatureId,
5974 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 return false;
5976 }
5977
5978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 CarrierConfigManager configManager =
5981 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005982 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Andrew Leea1239f22015-03-02 17:44:07 -08005987 }
5988
5989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005990 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005992 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 return false;
5994 }
5995
5996 final long identity = Binder.clearCallingIdentity();
5997 try {
5998 CarrierConfigManager configManager =
5999 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006000 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
Andrew Leea1239f22015-03-02 17:44:07 -08006005 }
6006
Andrew Lee9431b832015-03-09 18:46:45 -07006007 @Override
6008 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006009 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006010 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006011 }
6012
6013 @Override
6014 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
Andrew Lee9431b832015-03-09 18:46:45 -07006021 }
6022
Hall Liuf6668912018-10-31 17:05:23 -07006023 /**
6024 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6025 * support for the feature and device firmware support.
6026 *
6027 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6028 */
6029 @Override
6030 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006032 final Phone phone = getPhone(subscriptionId);
6033 if (phone == null) {
6034 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6035 return false;
6036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006038 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6040 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006041 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 return isCarrierSupported && isDeviceSupported;
6043 } finally {
6044 Binder.restoreCallingIdentity(identity);
6045 }
Hall Liu98187582018-01-22 19:15:32 -08006046 }
6047
Hall Liuf6668912018-10-31 17:05:23 -07006048 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006049 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6050 * RTT setting, will return true if the device and carrier both support RTT.
6051 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006052 */
6053 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 final long identity = Binder.clearCallingIdentity();
6055 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006056 boolean isRttSupported = isRttSupported(subscriptionId);
6057 boolean isUserRttSettingOn = Settings.Secure.getInt(
6058 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6059 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6060 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6061 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006065 }
6066
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006067 @Deprecated
6068 @Override
6069 public String getDeviceId(String callingPackage) {
6070 return getDeviceIdWithFeature(callingPackage, null);
6071 }
6072
Sanket Padawe7310cc72015-01-14 09:53:20 -08006073 /**
6074 * Returns the unique device ID of phone, for example, the IMEI for
6075 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6076 *
6077 * <p>Requires Permission:
6078 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6079 */
6080 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006081 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006082 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006083 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006084 return null;
6085 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006086 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006087 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006088 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006089 return null;
6090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 return phone.getDeviceId();
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006098 }
6099
Ping Sunc67b7c22016-03-02 19:16:45 +08006100 /**
6101 * {@hide}
6102 * Returns the IMS Registration Status on a particular subid
6103 *
6104 * @param subId
6105 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006106 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006107 Phone phone = getPhone(subId);
6108 if (phone != null) {
6109 return phone.isImsRegistered();
6110 } else {
6111 return false;
6112 }
6113 }
6114
Santos Cordon7a1885b2015-02-03 11:15:19 -08006115 @Override
6116 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 final long identity = Binder.clearCallingIdentity();
6118 try {
6119 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006123 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006124
Tyler Gunnf70ed162019-04-03 15:28:53 -07006125 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006126 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006127 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006129 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006130 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6131 }
6132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
6138 }
6139
6140 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006141 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 Phone phone = getPhone(subscriptionId);
6145 if (phone == null) {
6146 return null;
6147 }
6148 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
6152 }
6153
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006154 /**
6155 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006156 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006157 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 Phone phone = getPhone(subId);
6161 if (phone != null) {
6162 return phone.isWifiCallingEnabled();
6163 } else {
6164 return false;
6165 }
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006168 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006169 }
6170
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006171 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006172 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006173 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006174 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 final long identity = Binder.clearCallingIdentity();
6176 try {
6177 Phone phone = getPhone(subId);
6178 if (phone != null) {
6179 return phone.isVideoEnabled();
6180 } else {
6181 return false;
6182 }
6183 } finally {
6184 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006185 }
6186 }
6187
6188 /**
6189 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6190 * defined in {@link ImsRegistrationImplBase}.
6191 */
6192 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 Phone phone = getPhone(subId);
6196 if (phone != null) {
6197 return phone.getImsRegistrationTech();
6198 } else {
6199 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6200 }
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006203 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006204 }
6205
Stuart Scott8eef64f2015-04-08 15:13:54 -07006206 @Override
6207 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006208 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006209 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6210 return;
6211 }
6212
Svet Ganovcc087f82015-05-12 20:35:54 -07006213 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006214
Svet Ganovcc087f82015-05-12 20:35:54 -07006215 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006216 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6217 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006218 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006219 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006220 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006221 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6222 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006223 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006224 // There has been issues when Sms raw table somehow stores orphan
6225 // fragments. They lead to garbled message when new fragments come
6226 // in and combined with those stale ones. In case this happens again,
6227 // user can reset all network settings which will clean up this table.
6228 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006229 // Clean up IMS settings as well here.
6230 int slotId = getSlotIndex(subId);
6231 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6232 ImsManager.getInstance(mApp, slotId).factoryReset();
6233 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006234
6235 // Erase modem config if erase modem on network setting is enabled.
6236 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6237 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6238 if (configValue != null && Boolean.parseBoolean(configValue)) {
6239 sendEraseModemConfig(getDefaultPhone());
6240 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006243 }
6244 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006245
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006246 private void cleanUpSmsRawTable(Context context) {
6247 ContentResolver resolver = context.getContentResolver();
6248 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6249 resolver.delete(uri, null, null);
6250 }
6251
Narayan Kamath1c496c22015-04-16 14:40:19 +01006252 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006253 public String getSimLocaleForSubscriber(int subId) {
6254 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6255 final Phone phone = getPhone(subId);
6256 if (phone == null) {
6257 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006258 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 final long identity = Binder.clearCallingIdentity();
6261 try {
chen xu5d3637b2019-01-21 23:31:38 -08006262 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006263 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006264 if (info == null) {
6265 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6266 return null;
6267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 // Try and fetch the locale from the carrier properties or from the SIM language
6269 // preferences (EF-PL and EF-LI)...
6270 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006272 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6273 if (localeFromDefaultSim != null) {
6274 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6275 if (DBG) log("Using locale from subId: " + subId + " locale: "
6276 + localeFromDefaultSim);
6277 return localeFromDefaultSim.toLanguageTag();
6278 } else {
6279 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 }
6281 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 // The SIM language preferences only store a language (e.g. fr = French), not an
6284 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6285 // the SIM and carrier preferences does not include a country we add the country
6286 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006287 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006289 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 return mccLocale.toLanguageTag();
6291 }
6292
6293 if (DBG) log("No locale found - returning null");
6294 return null;
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006298 }
6299
6300 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006301 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6302 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006303 }
6304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 /**
6306 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6307 */
6308 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006309 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6310 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006311 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006312
Chenjie Yu1ba97252018-01-11 18:16:20 -08006313 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006314 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006315
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006316 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006317 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6318 * representing the state of the modem.
6319 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006320 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6321 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006322 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006323 */
6324 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006325 public void requestModemActivityInfo(ResultReceiver result) {
6326 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 ModemActivityInfo ret = null;
6332 synchronized (mLastModemActivityInfo) {
6333 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6334 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006335 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006336 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006338 int[] txTimeMs = info.getTransmitTimeMillis();
6339 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006341 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 }
6343 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006344 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6345 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 mLastModemActivityInfo.setIdleTimeMillis(
6347 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006348 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6349 mLastModemActivityInfo.setReceiveTimeMillis(
6350 info.getReceiveTimeMillis() + mLastModemActivityInfo
6351 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006352 }
Chen Xu13851032019-09-10 18:49:52 -07006353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6355 mLastModemActivityInfo.getSleepTimeMillis(),
6356 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006357 mLastModemActivityInfo.getTransmitTimeMillis(),
6358 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 Bundle bundle = new Bundle();
6361 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6362 result.send(0, bundle);
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006365 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006366 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006367
Siddharth Rayb8114062018-06-17 15:02:38 -07006368 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6369 // less than total activity duration.
6370 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6371 if (info == null) {
6372 return false;
6373 }
6374 int activityDurationMs =
6375 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6376 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006377 int[] txTimeMs = info.getTransmitTimeMillis();
6378 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6379 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006380 }
6381 return (info.isValid()
6382 && (info.getSleepTimeMillis() <= activityDurationMs)
6383 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006384 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006385 && (totalTxTimeMs <= activityDurationMs));
6386 }
6387
Jack Yu85bd38a2015-11-09 11:34:32 -08006388 /**
6389 * {@hide}
6390 * Returns the service state information on specified subscription.
6391 */
6392 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006393 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6394 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006396 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006397 return null;
6398 }
6399
Hall Liuf19c44f2018-11-27 14:38:17 -08006400 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6401 LocationAccessPolicy.checkLocationPermission(mApp,
6402 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6403 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006404 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006405 .setCallingPid(Binder.getCallingPid())
6406 .setCallingUid(Binder.getCallingUid())
6407 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006408 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006409 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6410 .build());
6411
6412 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6413 LocationAccessPolicy.checkLocationPermission(mApp,
6414 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6415 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006416 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006417 .setCallingPid(Binder.getCallingPid())
6418 .setCallingUid(Binder.getCallingUid())
6419 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006420 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006421 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6422 .build());
6423 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6424 boolean hasFinePermission =
6425 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6426 boolean hasCoarsePermission =
6427 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 final Phone phone = getPhone(subId);
6432 if (phone == null) {
6433 return null;
6434 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006435
Hall Liuf19c44f2018-11-27 14:38:17 -08006436 ServiceState ss = phone.getServiceState();
6437
6438 // Scrub out the location info in ServiceState depending on what level of access
6439 // the caller has.
6440 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006441 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6442 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006446 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006447
6448 /**
6449 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6450 *
6451 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6452 * voicemail ringtone.
6453 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6454 * PhoneAccount.
6455 */
6456 @Override
6457 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6461 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006462 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006469 }
6470
6471 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006472 * Sets the per-account voicemail ringtone.
6473 *
6474 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6475 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6476 *
6477 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6478 * voicemail ringtone.
6479 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6480 * PhoneAccount.
6481 */
6482 @Override
6483 public void setVoicemailRingtoneUri(String callingPackage,
6484 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006485 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006487 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6488 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6490 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6491 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493
6494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6497 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006498 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499 }
6500 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006503 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006504 }
6505
6506 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006507 * Returns whether vibration is set for voicemail notification in Phone settings.
6508 *
6509 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6510 * voicemail vibration setting.
6511 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6512 */
6513 @Override
6514 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6518 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006519 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006526 }
6527
Youhan Wange64578a2016-05-02 15:32:42 -07006528 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006529 * Sets the per-account voicemail vibration.
6530 *
6531 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6532 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6533 *
6534 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6535 * voicemail vibration setting.
6536 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6537 * specific PhoneAccount.
6538 */
6539 @Override
6540 public void setVoicemailVibrationEnabled(String callingPackage,
6541 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006542 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006544 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6545 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6547 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6548 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006549 }
6550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6554 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006555 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 }
6557 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006560 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006561 }
6562
6563 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006564 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6565 *
6566 * @throws SecurityException if the caller does not have the required permission
6567 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006568 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006570 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006571 }
6572
6573 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006574 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6575 * permission.
6576 *
6577 * @throws SecurityException if the caller does not have the required permission
6578 */
6579 private void enforceSendSmsPermission() {
6580 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6581 }
6582
6583 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006584 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006585 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006586 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006587 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006588 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006592 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 if (componentName == null) {
6594 throw new SecurityException(
6595 "Caller not current active visual voicemail package[null]");
6596 }
6597 String vvmPackage = componentName.getPackageName();
6598 if (!callingPackage.equals(vvmPackage)) {
6599 throw new SecurityException("Caller not current active visual voicemail package["
6600 + vvmPackage + "]");
6601 }
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006604 }
6605 }
6606
6607 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006608 * Return the application ID for the app type.
6609 *
6610 * @param subId the subscription ID that this request applies to.
6611 * @param appType the uicc app type.
6612 * @return Application ID for specificied app type, or null if no uicc.
6613 */
6614 @Override
6615 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006616 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006617 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618
6619 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006620 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 if (phone == null) {
6622 return null;
6623 }
6624 String aid = null;
6625 try {
6626 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6627 .getApplicationByType(appType).getAid();
6628 } catch (Exception e) {
6629 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6630 }
6631 return aid;
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006634 }
Youhan Wange64578a2016-05-02 15:32:42 -07006635 }
6636
Youhan Wang4001d252016-05-11 10:29:41 -07006637 /**
6638 * Return the Electronic Serial Number.
6639 *
6640 * @param subId the subscription ID that this request applies to.
6641 * @return ESN or null if error.
6642 */
6643 @Override
6644 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006645 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006646 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647
6648 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006649 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 if (phone == null) {
6651 return null;
6652 }
6653 String esn = null;
6654 try {
6655 esn = phone.getEsn();
6656 } catch (Exception e) {
6657 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6658 }
6659 return esn;
6660 } finally {
6661 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006662 }
Youhan Wang4001d252016-05-11 10:29:41 -07006663 }
6664
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006665 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006666 * Return the Preferred Roaming List Version.
6667 *
6668 * @param subId the subscription ID that this request applies to.
6669 * @return PRLVersion or null if error.
6670 */
6671 @Override
6672 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006673 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006674 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675
6676 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006677 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 if (phone == null) {
6679 return null;
6680 }
6681 String cdmaPrlVersion = null;
6682 try {
6683 cdmaPrlVersion = phone.getCdmaPrlVersion();
6684 } catch (Exception e) {
6685 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6686 }
6687 return cdmaPrlVersion;
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006690 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006691 }
6692
6693 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006694 * Get snapshot of Telephony histograms
6695 * @return List of Telephony histograms
6696 * @hide
6697 */
6698 @Override
6699 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6701 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702
6703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 return RIL.getTelephonyRILTimingHistograms();
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006709 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006710
6711 /**
6712 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006713 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6714 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006715 * Require system privileges. In the future we may add this to carrier APIs.
6716 *
Michele Berionne482f8202018-11-27 18:57:59 -08006717 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006718 */
6719 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006720 @TelephonyManager.SetCarrierRestrictionResult
6721 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006722 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006724
Michele Berionne482f8202018-11-27 18:57:59 -08006725 if (carrierRestrictionRules == null) {
6726 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006727 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 final long identity = Binder.clearCallingIdentity();
6730 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006731 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006732 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006736 }
6737
6738 /**
6739 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006740 * Get the allowed carrier list and the excluded carrier list, including the priority between
6741 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006742 * Require system privileges. In the future we may add this to carrier APIs.
6743 *
Michele Berionne482f8202018-11-27 18:57:59 -08006744 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006745 */
6746 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006747 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006748 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006749 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750
6751 final long identity = Binder.clearCallingIdentity();
6752 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006753 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6754 if (response instanceof CarrierRestrictionRules) {
6755 return (CarrierRestrictionRules) response;
6756 }
6757 // Response is an Exception of some kind,
6758 // which is signalled to the user as a NULL retval
6759 return null;
6760 } catch (Exception e) {
6761 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6762 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006766 }
6767
fionaxu59545b42016-05-25 15:53:37 -07006768 /**
6769 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6770 * @param subId the subscription ID that this action applies to.
6771 * @param enabled control enable or disable metered apns.
6772 * {@hide}
6773 */
6774 @Override
6775 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6776 enforceModifyPermission();
6777 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778
6779 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006780 if (phone == null) {
6781 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6782 return;
6783 }
6784 try {
6785 phone.carrierActionSetMeteredApnsEnabled(enabled);
6786 } catch (Exception e) {
6787 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 } finally {
6789 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006790 }
6791 }
6792
6793 /**
6794 * Action set from carrier signalling broadcast receivers to enable/disable radio
6795 * @param subId the subscription ID that this action applies to.
6796 * @param enabled control enable or disable radio.
6797 * {@hide}
6798 */
6799 @Override
6800 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6801 enforceModifyPermission();
6802 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803
6804 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006805 if (phone == null) {
6806 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6807 return;
6808 }
6809 try {
6810 phone.carrierActionSetRadioEnabled(enabled);
6811 } catch (Exception e) {
6812 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 } finally {
6814 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006815 }
6816 }
6817
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006818 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006819 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6820 * network status based on which carrier apps could apply actions accordingly,
6821 * enable/disable default url handler for example.
6822 *
6823 * @param subId the subscription ID that this action applies to.
6824 * @param report control start/stop reporting the default network status.
6825 * {@hide}
6826 */
6827 @Override
6828 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6829 enforceModifyPermission();
6830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831
6832 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006833 if (phone == null) {
6834 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6835 return;
6836 }
6837 try {
6838 phone.carrierActionReportDefaultNetworkStatus(report);
6839 } catch (Exception e) {
6840 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 } finally {
6842 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006843 }
6844 }
6845
6846 /**
fionaxud9622282017-07-17 17:51:30 -07006847 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6848 * @param subId the subscription ID that this action applies to.
6849 * {@hide}
6850 */
6851 @Override
6852 public void carrierActionResetAll(int subId) {
6853 enforceModifyPermission();
6854 final Phone phone = getPhone(subId);
6855 if (phone == null) {
6856 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6857 return;
6858 }
6859 try {
6860 phone.carrierActionResetAll();
6861 } catch (Exception e) {
6862 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6863 }
6864 }
6865
6866 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006867 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6868 * bug report is being generated.
6869 */
6870 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006871 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006872 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6873 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006874 writer.println("Permission Denial: can't dump Phone from pid="
6875 + Binder.getCallingPid()
6876 + ", uid=" + Binder.getCallingUid()
6877 + "without permission "
6878 + android.Manifest.permission.DUMP);
6879 return;
6880 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006881 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006882 }
Jack Yueb89b242016-06-22 13:27:47 -07006883
Brad Ebingerdac2f002018-04-03 15:17:52 -07006884 @Override
6885 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6886 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6887 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006888 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6889 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006890 }
6891
Jack Yueb89b242016-06-22 13:27:47 -07006892 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006893 * Get aggregated video call data usage since boot.
6894 *
6895 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6896 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006897 * {@hide}
6898 */
6899 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006900 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6902 null);
6903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 // NetworkStatsService keeps tracking the active network interface and identity. It
6907 // records the delta with the corresponding network identity.
6908 // We just return the total video call data usage snapshot since boot.
6909 Phone phone = getPhone(subId);
6910 if (phone != null) {
6911 return phone.getVtDataUsage(perUidStats);
6912 }
6913 return null;
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006916 }
Jack Yueb89b242016-06-22 13:27:47 -07006917 }
Jack Yu75ab2952016-07-08 14:29:33 -07006918
6919 /**
6920 * Policy control of data connection. Usually used when data limit is passed.
6921 * @param enabled True if enabling the data, otherwise disabling.
6922 * @param subId Subscription index
6923 * {@hide}
6924 */
6925 @Override
6926 public void setPolicyDataEnabled(boolean enabled, int subId) {
6927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 Phone phone = getPhone(subId);
6932 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006933 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 }
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006937 }
6938 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006939
6940 /**
6941 * Get Client request stats
6942 * @return List of Client Request Stats
6943 * @hide
6944 */
6945 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006946 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6947 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006949 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006950 return null;
6951 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006952 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 final long identity = Binder.clearCallingIdentity();
6955 try {
6956 if (phone != null) {
6957 return phone.getClientRequestStats();
6958 }
6959
6960 return null;
6961 } finally {
6962 Binder.restoreCallingIdentity(identity);
6963 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006964 }
6965
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006966 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006967 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006968 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006969 }
Jack Yueb4124c2017-02-16 15:32:43 -08006970
6971 /**
Grace Chen70990072017-03-24 17:21:30 -07006972 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006973 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006974 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006975 * @param state State of SIM (power down, power up, pass through)
6976 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6977 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6978 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006979 *
6980 **/
6981 @Override
Grace Chen70990072017-03-24 17:21:30 -07006982 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006983 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006984 Phone phone = PhoneFactory.getPhone(slotIndex);
6985
vagdeviaf9a5b92018-08-15 16:01:53 -07006986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006991 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 }
6993 } finally {
6994 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006995 }
6996 }
Shuo Qiandd210312017-04-12 22:11:33 +00006997
Tyler Gunn65d45c22017-06-05 11:22:26 -07006998 private boolean isUssdApiAllowed(int subId) {
6999 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007000 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007001 if (configManager == null) {
7002 return false;
7003 }
7004 PersistableBundle pb = configManager.getConfigForSubId(subId);
7005 if (pb == null) {
7006 return false;
7007 }
7008 return pb.getBoolean(
7009 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7010 }
7011
Shuo Qiandd210312017-04-12 22:11:33 +00007012 /**
7013 * Check if phone is in emergency callback mode
7014 * @return true if phone is in emergency callback mode
7015 * @param subId sub id
7016 */
goneil9c5f4872017-12-05 14:07:56 -08007017 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007018 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007019 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007020 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 if (phone != null) {
7025 return phone.isInEcm();
7026 } else {
7027 return false;
7028 }
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007031 }
7032 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007033
7034 /**
7035 * Get the current signal strength information for the given subscription.
7036 * Because this information is not updated when the device is in a low power state
7037 * it should not be relied-upon to be current.
7038 * @param subId Subscription index
7039 * @return the most recent cached signal strength info from the modem
7040 */
7041 @Override
7042 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 final long identity = Binder.clearCallingIdentity();
7044 try {
7045 Phone p = getPhone(subId);
7046 if (p == null) {
7047 return null;
7048 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 return p.getSignalStrength();
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007054 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007055
Pengquan Meng77b7f132018-08-22 14:49:57 -07007056 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007057 * Get the current modem radio state for the given slot.
7058 * @param slotIndex slot index.
7059 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007060 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007061 * @return the current radio power state from the modem
7062 */
7063 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007064 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007065 Phone phone = PhoneFactory.getPhone(slotIndex);
7066 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7068 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007069 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7070 }
7071
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 return phone.getRadioPowerState();
7075 } finally {
7076 Binder.restoreCallingIdentity(identity);
7077 }
7078 }
7079 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7080 }
7081
7082 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007083 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7084 *
7085 * <p>Requires one of the following permissions:
7086 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7087 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7088 * privileges.
7089 *
7090 * @param subId subscription id
7091 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7092 * {@code false}.
7093 */
7094 @Override
7095 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7097 null /* message */);
7098
Pengquan Menga1bb6272018-09-06 09:59:22 -07007099 boolean isEnabled = false;
7100 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007101 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007102 Phone phone = getPhone(subId);
7103 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007104 } catch (Exception e) {
7105 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7106 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007110 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007111 }
7112
7113
7114 /**
7115 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7116 *
7117 * <p> Requires permission:
7118 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7119 * privileges.
7120 *
7121 * @param subId subscription id
7122 * @param isEnabled {@code true} means enable, {@code false} means disable.
7123 */
7124 @Override
7125 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7127 mApp, subId, "setDataRoamingEnabled");
7128
Pengquan Menga1bb6272018-09-06 09:59:22 -07007129 final long identity = Binder.clearCallingIdentity();
7130 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007131 Phone phone = getPhone(subId);
7132 if (phone != null) {
7133 phone.setDataRoamingEnabled(isEnabled);
7134 }
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007137 }
7138 }
7139
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007140 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007141 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007142 TelephonyPermissions
7143 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007144 mApp, subId, "isManualNetworkSelectionAllowed");
7145
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007146 boolean isAllowed = true;
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007149 Phone phone = getPhone(subId);
7150 if (phone != null) {
7151 isAllowed = phone.isCspPlmnEnabled();
7152 }
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
7156 return isAllowed;
7157 }
7158
7159 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007160 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007161 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007162 try {
7163 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007164 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007165 } catch (SecurityException e) {
7166 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7167 // has carrier privileges on an active UICC
7168 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7169 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007170 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007171 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007172 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007176 UiccController uiccController = UiccController.getInstance();
7177 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007178 if (hasReadPermission) {
7179 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007180 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007181
7182 // Remove private info if the caller doesn't have access
7183 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7184 for (UiccCardInfo cardInfo : cardInfos) {
7185 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7186 // is available
7187 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7188 if (card == null || card.getUiccProfile() == null) {
7189 // assume no access if the card or profile is unavailable
7190 filteredInfos.add(cardInfo.getUnprivileged());
7191 continue;
7192 }
7193 UiccProfile profile = card.getUiccProfile();
7194 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7195 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7196 filteredInfos.add(cardInfo);
7197 } else {
7198 filteredInfos.add(cardInfo.getUnprivileged());
7199 }
7200 }
7201 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
7205 }
7206
7207 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007208 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007209 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7214 if (slots == null) {
7215 Rlog.i(LOG_TAG, "slots is null.");
7216 return null;
7217 }
7218
7219 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7220 for (int i = 0; i < slots.length; i++) {
7221 UiccSlot slot = slots[i];
7222 if (slot == null) {
7223 continue;
7224 }
7225
Jordan Liu7be7e652019-05-06 18:55:02 +00007226 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 UiccCard card = slot.getUiccCard();
7228 if (card != null) {
7229 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007230 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007231 cardId = slot.getEid();
7232 if (TextUtils.isEmpty(cardId)) {
7233 cardId = slot.getIccId();
7234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 }
7236
Jordan Liu857451f2019-05-09 16:35:35 -07007237 if (cardId != null) {
7238 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7239 // if cardId is an EID, it's all digits so this is fine
7240 cardId = IccUtils.stripTrailingFs(cardId);
7241 }
7242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 int cardState = 0;
7244 switch (slot.getCardState()) {
7245 case CARDSTATE_ABSENT:
7246 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7247 break;
7248 case CARDSTATE_PRESENT:
7249 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7250 break;
7251 case CARDSTATE_ERROR:
7252 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7253 break;
7254 case CARDSTATE_RESTRICTED:
7255 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7256 break;
7257 default:
7258 break;
7259
7260 }
7261
7262 infos[i] = new UiccSlotInfo(
7263 slot.isActive(),
7264 slot.isEuicc(),
7265 cardId,
7266 cardState,
7267 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007268 slot.isExtendedApduSupported(),
7269 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 }
7271 return infos;
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007274 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007275 }
7276
7277 @Override
7278 public boolean switchSlots(int[] physicalSlots) {
7279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007287 }
Jack Yu4c988042018-02-27 15:30:01 -08007288
7289 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007290 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 return UiccController.getInstance().getCardIdForDefaultEuicc();
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
7297 }
7298
7299 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007300 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7301 enforceModifyPermission();
7302 final Phone phone = getPhone(subId);
7303 if (phone == null) {
7304 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7305 return;
7306 }
7307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 phone.setRadioIndicationUpdateMode(filters, mode);
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
Jack Yu4c988042018-02-27 15:30:01 -08007314 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007315
7316 /**
goneil47ffb6e2018-04-06 15:40:58 -07007317 * A test API to reload the UICC profile.
7318 *
7319 * <p>Requires that the calling app has permission
7320 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7321 * @hide
7322 */
7323 @Override
7324 public void refreshUiccProfile(int subId) {
7325 enforceModifyPermission();
7326
7327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 Phone phone = getPhone(subId);
7330 if (phone == null) {
7331 return;
7332 }
7333 UiccCard uiccCard = phone.getUiccCard();
7334 if (uiccCard == null) {
7335 return;
7336 }
7337 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7338 if (uiccProfile == null) {
7339 return;
7340 }
7341 uiccProfile.refresh();
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
7345 }
7346
7347 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007348 * Returns false if the mobile data is disabled by default, otherwise return true.
7349 */
7350 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007351 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007352 }
7353
7354 /**
7355 * Returns true if the data roaming is enabled by default, i.e the system property
7356 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7357 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7358 */
7359 private boolean getDefaultDataRoamingEnabled(int subId) {
7360 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007362 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007363 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7364 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7365 return isDataRoamingEnabled;
7366 }
7367
7368 /**
7369 * Returns the default network type for the given {@code subId}, if the default network type is
7370 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7371 */
7372 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007373 List<Integer> list = TelephonyProperties.default_network();
7374 int phoneId = mSubscriptionController.getPhoneId(subId);
7375 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7376 return list.get(phoneId);
7377 }
7378 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007379 }
fionaxua13278b2018-03-21 00:08:13 -07007380
7381 @Override
7382 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007383 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 final Phone phone = getPhone(subId);
7389 if (phone == null) {
7390 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7391 return;
7392 }
chen xueaba88a2019-03-15 13:15:10 -07007393 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7394 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 } finally {
7396 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007397 }
fionaxua13278b2018-03-21 00:08:13 -07007398 }
7399
7400 @Override
7401 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007402 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403
7404 final long identity = Binder.clearCallingIdentity();
7405 try {
7406 final Phone phone = getPhone(subId);
7407 if (phone == null) {
7408 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7409 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7410 }
7411 return phone.getCarrierIdListVersion();
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007414 }
fionaxua13278b2018-03-21 00:08:13 -07007415 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007416
7417 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007418 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7419 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007421 mApp, subId, callingPackage, callingFeatureId,
7422 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007423 return -1;
7424 }
7425
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
7432 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007433
7434 @Override
7435 public int getCdmaRoamingMode(int subId) {
7436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7437 mApp, subId, "getCdmaRoamingMode");
7438
7439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
7445 }
7446
7447 @Override
7448 public boolean setCdmaRoamingMode(int subId, int mode) {
7449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7450 mApp, subId, "setCdmaRoamingMode");
7451
7452 final long identity = Binder.clearCallingIdentity();
7453 try {
7454 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
7458 }
7459
7460 @Override
7461 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7463 mApp, subId, "setCdmaSubscriptionMode");
7464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
7471 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007472
sqianc5eccab2018-10-19 18:46:41 -07007473 @Override
sqian8c685422019-02-22 15:55:18 -08007474 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007475 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007477 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7478 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007479 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7480 }
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
sqian854d44b2018-12-12 16:48:18 -08007483 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7484 for (Phone phone: PhoneFactory.getPhones()) {
7485 if (phone.getEmergencyNumberTracker() != null
7486 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7487 emergencyNumberListInternal.put(
7488 phone.getSubId(),
7489 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7490 }
sqian11b7a0e2018-12-05 18:48:28 -08007491 }
sqian854d44b2018-12-12 16:48:18 -08007492 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
sqianc5eccab2018-10-19 18:46:41 -07007496 }
7497
7498 @Override
sqian8c685422019-02-22 15:55:18 -08007499 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007500 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007501 if (!exactMatch) {
7502 TelephonyPermissions
7503 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007504 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007505 }
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
sqian854d44b2018-12-12 16:48:18 -08007508 for (Phone phone: PhoneFactory.getPhones()) {
7509 if (phone.getEmergencyNumberTracker() != null
7510 && phone.getEmergencyNumberTracker() != null) {
7511 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7512 number, exactMatch)) {
7513 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007514 }
7515 }
sqian11b7a0e2018-12-05 18:48:28 -08007516 }
7517 return false;
7518 } finally {
7519 Binder.restoreCallingIdentity(identity);
7520 }
7521 }
7522
sqianf4ca7ed2019-01-15 18:32:07 -08007523 /**
7524 * Update emergency number list for test mode.
7525 */
7526 @Override
7527 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7528 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7529 "updateEmergencyNumberListTestMode");
7530
7531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 for (Phone phone: PhoneFactory.getPhones()) {
7534 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7535 if (tracker != null) {
7536 tracker.executeEmergencyNumberTestModeCommand(action, num);
7537 }
7538 }
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
7542 }
7543
7544 /**
7545 * Get the full emergency number list for test mode.
7546 */
7547 @Override
7548 public List<String> getEmergencyNumberListTestMode() {
7549 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7550 "getEmergencyNumberListTestMode");
7551
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Set<String> emergencyNumbers = new HashSet<>();
7555 for (Phone phone: PhoneFactory.getPhones()) {
7556 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7557 if (tracker != null) {
7558 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7559 emergencyNumbers.add(num.getNumber());
7560 }
7561 }
7562 }
7563 return new ArrayList<>(emergencyNumbers);
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
7567 }
7568
chen xud6b45bd2018-10-30 22:27:10 -07007569 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007570 public int getEmergencyNumberDbVersion(int subId) {
7571 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7572
7573 final long identity = Binder.clearCallingIdentity();
7574 try {
7575 final Phone phone = getPhone(subId);
7576 if (phone == null) {
7577 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7578 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7579 }
7580 return phone.getEmergencyNumberDbVersion();
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
7584 }
7585
7586 @Override
7587 public void notifyOtaEmergencyNumberDbInstalled() {
7588 enforceModifyPermission();
7589
7590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 for (Phone phone: PhoneFactory.getPhones()) {
7593 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7594 if (tracker != null) {
7595 tracker.updateOtaEmergencyNumberDatabase();
7596 }
7597 }
7598 } finally {
7599 Binder.restoreCallingIdentity(identity);
7600 }
7601 }
7602
7603 @Override
7604 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7605 enforceActiveEmergencySessionPermission();
7606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 for (Phone phone: PhoneFactory.getPhones()) {
7610 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7611 if (tracker != null) {
7612 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7613 }
7614 }
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
7619
7620 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007621 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7622 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7623 Phone phone = getPhone(subId);
7624 if (phone == null) {
7625 return null;
7626 }
7627 final long identity = Binder.clearCallingIdentity();
7628 try {
7629 UiccProfile profile = UiccController.getInstance()
7630 .getUiccProfileForPhone(phone.getPhoneId());
7631 if (profile != null) {
7632 return profile.getCertsFromCarrierPrivilegeAccessRules();
7633 }
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 return null;
7638 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007639
7640 /**
7641 * Enable or disable a modem stack.
7642 */
7643 @Override
7644 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7645 enforceModifyPermission();
7646
7647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 Phone phone = PhoneFactory.getPhone(slotIndex);
7650 if (phone == null) {
7651 return false;
7652 } else {
7653 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7654 }
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
Michelecea4cf22018-12-21 15:00:11 -08007659
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007660 /**
7661 * Whether a modem stack is enabled or not.
7662 */
7663 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007664 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7665 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007666 Phone phone = PhoneFactory.getPhone(slotIndex);
7667 if (phone == null) return false;
7668
7669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007670 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7671 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007672 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7673 }
7674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007677 try {
7678 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7679 } catch (NoSuchElementException ex) {
7680 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7681 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 }
7686
Michelecea4cf22018-12-21 15:00:11 -08007687 @Override
Michele0ea7d782019-03-19 14:58:42 -07007688 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007689 enforceModifyPermission();
7690
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007694 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007695 .commit();
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
7699 }
7700
7701 @Override
Michele0ea7d782019-03-19 14:58:42 -07007702 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007703 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007705 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7706 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007707 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007708 }
Michelecea4cf22018-12-21 15:00:11 -08007709
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
Michele0ea7d782019-03-19 14:58:42 -07007712 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
7716 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007717
Michele0ea7d782019-03-19 14:58:42 -07007718 @TelephonyManager.IsMultiSimSupportedResult
7719 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007720 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7721 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7722 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007723 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7724 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007725 }
7726 // Check if the hardware supports multisim functionality. If usage of multisim is not
7727 // supported by the modem, indicate that it is restricted.
7728 PhoneCapability staticCapability =
7729 mPhoneConfigurationManager.getStaticPhoneCapability();
7730 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007731 loge("isMultiSimSupportedInternal: no static configuration available");
7732 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007733 }
7734 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007735 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7736 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007737 }
7738 // Check if support of multiple SIMs is restricted by carrier
7739 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007740 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007741 }
7742
Michele0ea7d782019-03-19 14:58:42 -07007743 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007744 }
7745
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007746 /**
7747 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007748 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7749 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7750 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007751 * @param numOfSims number of active sims we want to switch to
7752 */
7753 @Override
7754 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007755 if (numOfSims == 1) {
7756 enforceModifyPermission();
7757 } else {
7758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7759 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7760 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007761 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007762
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007763 try {
Michele30b57b22019-03-01 12:01:14 -08007764 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007765 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007766 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7767 return;
7768 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007769 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
7773 }
7774
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007775 @Override
7776 public boolean isApplicationOnUicc(int subId, int appType) {
7777 enforceReadPrivilegedPermission("isApplicationOnUicc");
7778 Phone phone = getPhone(subId);
7779 if (phone == null) {
7780 return false;
7781 }
7782 final long identity = Binder.clearCallingIdentity();
7783 try {
7784 UiccCard uiccCard = phone.getUiccCard();
7785 if (uiccCard == null) {
7786 return false;
7787 }
7788 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7789 if (uiccProfile == null) {
7790 return false;
7791 }
7792 if (TelephonyManager.APPTYPE_SIM <= appType
7793 && appType <= TelephonyManager.APPTYPE_ISIM) {
7794 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7795 }
7796 return false;
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
7799 }
7800 }
7801
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007802 /**
chen xub4baa772019-04-03 10:23:41 -07007803 * Get whether making changes to modem configurations will trigger reboot.
7804 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007805 */
7806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007807 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7808 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007810 mApp, subId, callingPackage, callingFeatureId,
7811 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007812 return false;
7813 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007814 final long identity = Binder.clearCallingIdentity();
7815 try {
7816 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
7820 }
7821
Nathan Harold29f5f052019-02-15 13:41:57 -08007822 private void updateModemStateMetrics() {
7823 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7824 // TODO: check the state for each modem if the api is ready.
7825 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7826 }
7827
Pengquan Meng3889a572019-01-23 11:16:29 -08007828 @Override
7829 public int[] getSlotsMapping() {
7830 enforceReadPrivilegedPermission("getSlotsMapping");
7831
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7835 // All logical slots should have a mapping to a physical slot.
7836 int[] logicalSlotsMapping = new int[phoneCount];
7837 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7838 for (int i = 0; i < slotInfos.length; i++) {
7839 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7840 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7841 }
7842 }
7843 return logicalSlotsMapping;
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007848
7849 /**
7850 * Get the IRadio HAL Version
7851 */
7852 @Override
7853 public int getRadioHalVersion() {
7854 Phone phone = getDefaultPhone();
7855 if (phone == null) return -1;
7856 HalVersion hv = phone.getHalVersion();
7857 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7858 return hv.major * 100 + hv.minor;
7859 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007860
7861 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007862 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7863 * corresponding network requests on a subId.
7864 *
7865 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007866 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007867 * 2) APN is un-metered for this subscription, or
7868 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7869 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7870 *
7871 * @return whether data is allowed for a apn type.
7872 *
7873 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007874 */
7875 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007876 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007877 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7878 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007879
7880 // Now that all security checks passes, perform the operation as ourselves.
7881 final long identity = Binder.clearCallingIdentity();
7882 try {
7883 Phone phone = getPhone(subId);
7884 if (phone == null) return false;
7885
Jack Yu41407ee2019-05-13 16:54:09 -07007886 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007887 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
7890 }
7891 }
7892
7893 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007894 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007895 enforceReadPrivilegedPermission("isApnMetered");
7896
7897 // Now that all security checks passes, perform the operation as ourselves.
7898 final long identity = Binder.clearCallingIdentity();
7899 try {
7900 Phone phone = getPhone(subId);
7901 if (phone == null) return true; // By default return true.
7902
Jack Yu41407ee2019-05-13 16:54:09 -07007903 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
7907 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007908
7909 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007910 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7911 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7912 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7913 if (iccRecords == null) {
7914 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7915 return false;
7916 }
7917 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7918 }
7919
7920 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007921 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7922 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7923 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7924 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7925 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7926 }
7927 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7928 Intent intent = new Intent();
7929 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7930 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7931 // Bring up choose default SMS subscription dialog right now
7932 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7933 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7934 mApp.startActivity(intent);
7935 }
chen xud5ca2d52019-05-28 15:20:57 -07007936
7937 @Override
7938 public String getMmsUAProfUrl(int subId) {
7939 //TODO investigate if this API should require proper permission check in R b/133791609
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7943 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7944 } finally {
7945 Binder.restoreCallingIdentity(identity);
7946 }
7947 }
7948
7949 @Override
7950 public String getMmsUserAgent(int subId) {
7951 //TODO investigate if this API should require proper permission check in R b/133791609
7952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7955 .getString(com.android.internal.R.string.config_mms_user_agent);
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
7959 }
Jack Yub07d4972019-05-28 16:12:25 -07007960
7961 @Override
7962 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7963 enforceModifyPermission();
7964
7965 // Now that all security checks passes, perform the operation as ourselves.
7966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 Phone phone = getPhone(subId);
7969 if (phone == null) return false;
7970
7971 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7972 } finally {
7973 Binder.restoreCallingIdentity(identity);
7974 }
7975 }
7976
7977 @Override
7978 public boolean isDataAllowedInVoiceCall(int subId) {
7979 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7980
7981 // Now that all security checks passes, perform the operation as ourselves.
7982 final long identity = Binder.clearCallingIdentity();
7983 try {
7984 Phone phone = getPhone(subId);
7985 if (phone == null) return false;
7986
7987 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
7990 }
7991 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007992
7993 /**
7994 * Updates whether conference event pacakge handling is enabled.
7995 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7996 * otherwise.
7997 */
7998 @Override
7999 public void setCepEnabled(boolean isCepEnabled) {
8000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8001
8002 final long identity = Binder.clearCallingIdentity();
8003 try {
8004 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8005 for (Phone phone : PhoneFactory.getPhones()) {
8006 Phone defaultPhone = phone.getImsPhone();
8007 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8008 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8009 ImsPhoneCallTracker imsPhoneCallTracker =
8010 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8011 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8012 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8013 + imsPhone.getMsisdn());
8014 }
8015 }
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
allenwtsu46dcc572020-01-08 18:24:03 +08008020
8021 /**
8022 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8023 *
8024 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8025 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8026 * before being read.
8027 */
8028 @Override
8029 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8030 isCompressed) {
8031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8032 mApp, subId, "notifyRcsAutoConfigurationReceived");
8033 try {
8034 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8035 if (configBinder == null) {
8036 Rlog.e(LOG_TAG, "null result for getImsConfig");
8037 } else {
8038 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8039 }
8040 } catch (RemoteException e) {
8041 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8042 }
8043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008044}