blob: 76cf5f96100df1d22ee767eb93427996b343c216 [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;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070087import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-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 Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800167import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800280 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 * Experiment flag to enable erase modem config on reset network, default value is false
306 */
307 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
308 "reset_network_erase_modem_config_enabled";
309
310 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700311 * A request object to use for transmitting data to an ICC.
312 */
313 private static final class IccAPDUArgument {
314 public int channel, cla, command, p1, p2, p3;
315 public String data;
316
317 public IccAPDUArgument(int channel, int cla, int command,
318 int p1, int p2, int p3, String data) {
319 this.channel = channel;
320 this.cla = cla;
321 this.command = command;
322 this.p1 = p1;
323 this.p2 = p2;
324 this.p3 = p3;
325 this.data = data;
326 }
327 }
328
329 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class ManualNetworkSelectionArgument {
333 public OperatorInfo operatorInfo;
334 public boolean persistSelection;
335
336 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
337 this.operatorInfo = operatorInfo;
338 this.persistSelection = persistSelection;
339 }
340 }
341
342 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
344 * request after sending. The main thread will notify the request when it is complete.
345 */
346 private static final class MainThreadRequest {
347 /** The argument to use for the request */
348 public Object argument;
349 /** The result of the request that is run on the main thread */
350 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800351 // The subscriber id that this request applies to. Defaults to
352 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
353 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Nathan Harold92bed182018-10-12 18:16:49 -0700355 // In cases where subId is unavailable, the caller needs to specify the phone.
356 public Phone phone;
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 public WorkSource workSource;
359
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 public MainThreadRequest(Object argument) {
361 this.argument = argument;
362 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363
Nathan Harold92bed182018-10-12 18:16:49 -0700364 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
365 this.argument = argument;
366 if (phone != null) {
367 this.phone = phone;
368 }
369 this.workSource = workSource;
370 }
371
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800373 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800374 if (subId != null) {
375 this.subId = subId;
376 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 }
380
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800381 private static final class IncomingThirdPartyCallArgs {
382 public final ComponentName component;
383 public final String callId;
384 public final String callerDisplayName;
385
386 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
387 String callerDisplayName) {
388 this.component = component;
389 this.callId = callId;
390 this.callerDisplayName = callerDisplayName;
391 }
392 }
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 /**
395 * A handler that processes messages on the main thread in the phone process. Since many
396 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
397 * inbound binder threads to the main thread in the phone process. The Binder thread
398 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
399 * on, which will be notified when the operation completes and will contain the result of the
400 * request.
401 *
402 * <p>If a MainThreadRequest object is provided in the msg.obj field,
403 * note that request.result must be set to something non-null for the calling thread to
404 * unblock.
405 */
406 private final class MainThreadHandler extends Handler {
407 @Override
408 public void handleMessage(Message msg) {
409 MainThreadRequest request;
410 Message onCompleted;
411 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800414 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 case CMD_HANDLE_USSD_REQUEST: {
418 request = (MainThreadRequest) msg.obj;
419 final Phone phone = getPhoneFromRequest(request);
420 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
421 String ussdRequest = ussdObject.first;
422 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 if (!isUssdApiAllowed(request.subId)) {
425 // Carrier does not support use of this API, return failure.
426 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
427 UssdResponse response = new UssdResponse(ussdRequest, null);
428 Bundle returnData = new Bundle();
429 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
430 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700431
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 request.result = true;
433 notifyRequester(request);
434 return;
435 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700436
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 try {
438 request.result = phone != null
439 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
440 } catch (CallStateException cse) {
441 request.result = false;
442 }
443 // Wake up the requesting thread
444 notifyRequester(request);
445 break;
pkanwar32d516d2016-10-14 19:37:38 -0700446 }
447
Yorke Lee716f67e2015-06-17 15:39:16 -0700448 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 final Phone phone = getPhoneFromRequest(request);
451 request.result = phone != null ?
452 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
453 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 if (uiccCard == null) {
464 loge("iccTransmitApduLogicalChannel: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
469 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 iccArgument.channel, iccArgument.cla, iccArgument.command,
472 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 break;
476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800486 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800488 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 } else {
490 loge("iccTransmitApduLogicalChannel: Unknown exception");
491 }
492 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduBasicChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 } else {
505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
506 request);
507 uiccCard.iccTransmitApduBasicChannel(
508 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
509 iccArgument.p3, iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 if (ar.result == null) {
521 loge("iccTransmitApduBasicChannel: Empty response");
522 } else if (ar.exception instanceof CommandException) {
523 loge("iccTransmitApduBasicChannel: CommandException: " +
524 ar.exception);
525 } else {
526 loge("iccTransmitApduBasicChannel: Unknown exception");
527 }
528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 break;
531
532 case CMD_EXCHANGE_SIM_IO:
533 request = (MainThreadRequest) msg.obj;
534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 if (uiccCard == null) {
537 loge("iccExchangeSimIO: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
542 request);
543 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
544 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
545 iccArgument.data, onCompleted);
546 }
547 break;
548
549 case EVENT_EXCHANGE_SIM_IO_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6f, 0, (byte[])null);
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 case CMD_SEND_ENVELOPE:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 if (uiccCard == null) {
564 loge("sendEnvelopeWithStatus: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
569 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 break;
572
573 case EVENT_SEND_ENVELOPE_DONE:
574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("sendEnvelopeWithStatus: Empty response");
582 } else if (ar.exception instanceof CommandException) {
583 loge("sendEnvelopeWithStatus: CommandException: " +
584 ar.exception);
585 } else {
586 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
587 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 case CMD_OPEN_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 if (uiccCard == null) {
597 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800598 request.result = new IccOpenLogicalChannelResponse(-1,
599 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800603 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
604 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case EVENT_OPEN_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 int[] result = (int[]) ar.result;
614 int channelId = result[0];
615 byte[] selectResponse = null;
616 if (result.length > 1) {
617 selectResponse = new byte[result.length - 1];
618 for (int i = 1; i < result.length; ++i) {
619 selectResponse[i - 1] = (byte) result[i];
620 }
621 }
622 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 if (ar.result == null) {
626 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 if (ar.exception != null) {
629 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
630 }
631
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700633 if (ar.exception instanceof CommandException) {
634 CommandException.Error error =
635 ((CommandException) (ar.exception)).getCommandError();
636 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700638 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 }
642 openChannelResp = new IccOpenLogicalChannelResponse(
643 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700645 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case CMD_CLOSE_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900654 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
658 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
662 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800663 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
664 break;
665
666 case CMD_NV_READ_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 request.result = "";
680 if (ar.result == null) {
681 loge("nvReadItem: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("nvReadItem: CommandException: " +
684 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800686 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Jake Hambye994d462014-02-03 13:10:13 -0800692 case CMD_NV_WRITE_ITEM:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
695 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_ITEM_DONE:
701 handleNullReturnEvent(msg, "nvWriteItem");
702 break;
703
704 case CMD_NV_WRITE_CDMA_PRL:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_WRITE_CDMA_PRL_DONE:
711 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800715 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700716 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
chen xu6dac5ab2018-10-26 17:39:23 -0700720 case EVENT_RESET_MODEM_CONFIG_DONE:
721 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 case CMD_GET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700727 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 break;
729
730 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result; // Integer
735 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800736 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 if (ar.result == null) {
738 loge("getPreferredNetworkType: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("getPreferredNetworkType: CommandException: " +
741 ar.exception);
742 } else {
743 loge("getPreferredNetworkType: Unknown exception");
744 }
745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case CMD_SET_PREFERRED_NETWORK_TYPE:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
752 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700753 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 break;
755
756 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
757 handleNullReturnEvent(msg, "setPreferredNetworkType");
758 break;
759
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
761 request = (MainThreadRequest)msg.obj;
762 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
766 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
767 ar = (AsyncResult)msg.obj;
768 request = (MainThreadRequest)ar.userObj;
769 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000771 break;
772
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 case CMD_SET_VOICEMAIL_NUMBER:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
776 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800777 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
778 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800779 break;
780
781 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
782 handleNullReturnEvent(msg, "setVoicemailNumber");
783 break;
784
Stuart Scott54788802015-03-30 13:18:01 -0700785 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
788 request);
789 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
793 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
794 break;
795
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 case CMD_PERFORM_NETWORK_SCAN:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
799 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
800 break;
801
802 case EVENT_PERFORM_NETWORK_SCAN_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 CellNetworkScanResult cellScanResult;
806 if (ar.exception == null && ar.result != null) {
807 cellScanResult = new CellNetworkScanResult(
808 CellNetworkScanResult.STATUS_SUCCESS,
809 (List<OperatorInfo>) ar.result);
810 } else {
811 if (ar.result == null) {
812 loge("getCellNetworkScanResults: Empty response");
813 }
814 if (ar.exception != null) {
815 loge("getCellNetworkScanResults: Exception: " + ar.exception);
816 }
817 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
818 if (ar.exception instanceof CommandException) {
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
821 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
823 } else if (error == CommandException.Error.GENERIC_FAILURE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
825 }
826 }
827 cellScanResult = new CellNetworkScanResult(errorCode, null);
828 }
829 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700830 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result = true;
848 } else {
849 request.result = false;
850 loge("setNetworkSelectionModeManual " + ar.exception);
851 }
852 notifyRequester(request);
853 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700854 break;
855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 case CMD_GET_MODEM_ACTIVITY_INFO:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700859 if (defaultPhone != null) {
860 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
861 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700862 break;
863
864 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("queryModemActivityInfo: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("queryModemActivityInfo: CommandException: " +
874 ar.exception);
875 } else {
876 loge("queryModemActivityInfo: Unknown exception");
877 }
878 }
Amit Mahajand4766222016-01-28 15:28:28 -0800879 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
880 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800881 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700884 break;
885
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 case CMD_SET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800888 CarrierRestrictionRules argument =
889 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800891 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 break;
893
894 case EVENT_SET_ALLOWED_CARRIERS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800900 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
901 if (ar.exception instanceof CommandException) {
902 loge("setAllowedCarriers: CommandException: " + ar.exception);
903 CommandException.Error error =
904 ((CommandException) (ar.exception)).getCommandError();
905 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
906 request.result =
907 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 } else {
910 loge("setAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case CMD_GET_ALLOWED_CARRIERS:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
922 case EVENT_GET_ALLOWED_CARRIERS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800928 request.result = new IllegalStateException(
929 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 if (ar.result == null) {
931 loge("getAllowedCarriers: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("getAllowedCarriers: CommandException: " +
934 ar.exception);
935 } else {
936 loge("getAllowedCarriers: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958
959 case CMD_GET_FORBIDDEN_PLMNS:
960 request = (MainThreadRequest) msg.obj;
961 uiccCard = getUiccCardFromRequest(request);
962 if (uiccCard == null) {
963 loge("getForbiddenPlmns() UiccCard is null");
964 request.result = new IllegalArgumentException(
965 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800967 break;
968 }
969 Integer appType = (Integer) request.argument;
970 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
971 if (uiccApp == null) {
972 loge("getForbiddenPlmns() no app with specified type -- "
973 + appType);
974 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977 } else {
978 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
979 + " specified type -- " + appType);
980 }
981 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
982 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
983 onCompleted);
984 break;
985
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000986 case CMD_SWITCH_SLOTS:
987 request = (MainThreadRequest) msg.obj;
988 int[] physicalSlots = (int[]) request.argument;
989 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
990 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
991 break;
992
993 case EVENT_SWITCH_SLOTS_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
998 break;
999 case CMD_GET_NETWORK_SELECTION_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1002 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1003 break;
1004
1005 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception != null) {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1010 } else {
1011 int mode = ((int[]) ar.result)[0];
1012 if (mode == 0) {
1013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1014 } else {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1016 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001018 notifyRequester(request);
1019 break;
1020 case CMD_GET_CDMA_ROAMING_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1023 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1024 break;
1025 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception != null) {
1029 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1030 } else {
1031 request.result = ((int[]) ar.result)[0];
1032 }
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_ROAMING_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1038 int mode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
1046 break;
1047 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1050 int subscriptionMode = (int) request.argument;
1051 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1052 break;
1053 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 request.result = ar.exception == null;
1057 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001058 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 case CMD_GET_ALL_CELL_INFO:
1060 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001062 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 case EVENT_GET_ALL_CELL_INFO_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001067 // If a timeout occurs, the response will be null
1068 request.result = (ar.exception == null && ar.result != null)
1069 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 synchronized (request) {
1071 request.notifyAll();
1072 }
1073 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 case CMD_REQUEST_CELL_INFO_UPDATE:
1075 request = (MainThreadRequest) msg.obj;
1076 request.phone.requestCellInfoUpdate(request.workSource,
1077 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1078 break;
1079 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1083 try {
1084 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001086 cb.onError(
1087 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1088 ar.exception.getClass().getName(),
1089 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001092 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else {
1094 // use the result as returned
1095 cb.onCellInfo((List<CellInfo>) ar.result);
1096 }
1097 } catch (RemoteException re) {
1098 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1099 }
1100 break;
1101 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 request = (MainThreadRequest) msg.obj;
1103 WorkSource ws = (WorkSource) request.argument;
1104 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001105 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001106 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null) {
1111 request.result = ar.result;
1112 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001113 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001114 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001115 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001116 }
1117
1118 synchronized (request) {
1119 request.notifyAll();
1120 }
1121 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001122 case CMD_MODEM_REBOOT:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001125 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001126 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001127 case EVENT_CMD_MODEM_REBOOT_DONE:
1128 handleNullReturnEvent(msg, "rebootModem");
1129 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001130 case CMD_REQUEST_ENABLE_MODEM:
1131 request = (MainThreadRequest) msg.obj;
1132 boolean enable = (boolean) request.argument;
1133 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001134 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001135 PhoneConfigurationManager.getInstance()
1136 .enablePhone(request.phone, enable, onCompleted);
1137 break;
1138 case EVENT_ENABLE_MODEM_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001142 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001143 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 if ((boolean) request.result) {
1145 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1146 updateModemStateMetrics();
1147 } else {
1148 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1149 + ar.exception);
1150 }
1151 notifyRequester(request);
1152 break;
1153 case CMD_GET_MODEM_STATUS:
1154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1156 PhoneConfigurationManager.getInstance()
1157 .getPhoneStatusFromModem(request.phone, onCompleted);
1158 break;
1159 case EVENT_GET_MODEM_STATUS_DONE:
1160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 int id = request.phone.getPhoneId();
1163 if (ar.exception == null && ar.result != null) {
1164 request.result = ar.result;
1165 //update the cache as modem status has changed
1166 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1167 (boolean) request.result);
1168 } else {
1169 // Return true if modem status cannot be retrieved. For most cases,
1170 // modem status is on. And for older version modems, GET_MODEM_STATUS
1171 // and disable modem are not supported. Modem is always on.
1172 // TODO: this should be fixed in R to support a third
1173 // status UNKNOWN b/131631629
1174 request.result = true;
1175 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1176 + ar.exception);
1177 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001178 notifyRequester(request);
1179 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001180 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null && ar.result != null) {
1184 request.result = ar.result;
1185 } else {
1186 request.result = -1;
1187 loge("Failed to set Forbidden Plmns");
1188 if (ar.result == null) {
1189 loge("setForbidenPlmns: Empty response");
1190 } else if (ar.exception != null) {
1191 loge("setForbiddenPlmns: Exception: " + ar.exception);
1192 request.result = -1;
1193 } else {
1194 loge("setForbiddenPlmns: Unknown exception");
1195 }
1196 }
1197 notifyRequester(request);
1198 break;
1199 case CMD_SET_FORBIDDEN_PLMNS:
1200 request = (MainThreadRequest) msg.obj;
1201 uiccCard = getUiccCardFromRequest(request);
1202 if (uiccCard == null) {
1203 loge("setForbiddenPlmns: UiccCard is null");
1204 request.result = -1;
1205 notifyRequester(request);
1206 break;
1207 }
1208 Pair<Integer, List<String>> setFplmnsArgs =
1209 (Pair<Integer, List<String>>) request.argument;
1210 appType = setFplmnsArgs.first;
1211 List<String> fplmns = setFplmnsArgs.second;
1212 uiccApp = uiccCard.getApplicationByType(appType);
1213 if (uiccApp == null) {
1214 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1215 request.result = -1;
1216 loge("Failed to get UICC App");
1217 notifyRequester(request);
1218 } else {
1219 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1220 ((SIMRecords) uiccApp.getIccRecords())
1221 .setForbiddenPlmns(onCompleted, fplmns);
1222 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001223 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001224 case CMD_ERASE_MODEM_CONFIG:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1227 defaultPhone.eraseModemConfig(onCompleted);
1228 break;
1229 case EVENT_ERASE_MODEM_CONFIG_DONE:
1230 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001231 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 default:
1233 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1234 break;
1235 }
1236 }
Jake Hambye994d462014-02-03 13:10:13 -08001237
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 private void notifyRequester(MainThreadRequest request) {
1239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 }
1243
Jake Hambye994d462014-02-03 13:10:13 -08001244 private void handleNullReturnEvent(Message msg, String command) {
1245 AsyncResult ar = (AsyncResult) msg.obj;
1246 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null) {
1248 request.result = true;
1249 } else {
1250 request.result = false;
1251 if (ar.exception instanceof CommandException) {
1252 loge(command + ": CommandException: " + ar.exception);
1253 } else {
1254 loge(command + ": Unknown exception");
1255 }
1256 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001257 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
1261 /**
1262 * Posts the specified command to be executed on the main thread,
1263 * waits for the request to complete, and returns the result.
1264 * @see #sendRequestAsync
1265 */
1266 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001267 return sendRequest(
1268 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001269 }
1270
1271 /**
1272 * Posts the specified command to be executed on the main thread,
1273 * waits for the request to complete, and returns the result.
1274 * @see #sendRequestAsync
1275 */
1276 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1277 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001278 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001286 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001287 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001288 }
1289
1290 /**
1291 * Posts the specified command to be executed on the main thread,
1292 * waits for the request to complete, and returns the result.
1293 * @see #sendRequestAsync
1294 */
Nathan Harold92bed182018-10-12 18:16:49 -07001295 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1296 return sendRequest(command, argument, subId, null, workSource);
1297 }
1298
1299 /**
1300 * Posts the specified command to be executed on the main thread,
1301 * waits for the request to complete, and returns the result.
1302 * @see #sendRequestAsync
1303 */
1304 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1305 return sendRequest(
1306 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1307 }
1308
1309 /**
1310 * Posts the specified command to be executed on the main thread,
1311 * waits for the request to complete, and returns the result.
1312 * @see #sendRequestAsync
1313 */
1314 private Object sendRequest(
1315 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1317 throw new RuntimeException("This method will deadlock if called from the main thread.");
1318 }
1319
Nathan Harold92bed182018-10-12 18:16:49 -07001320 MainThreadRequest request = null;
1321 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1322 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1323 } else if (phone != null) {
1324 request = new MainThreadRequest(argument, phone, workSource);
1325 } else {
1326 request = new MainThreadRequest(argument, subId, workSource);
1327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 Message msg = mMainThreadHandler.obtainMessage(command, request);
1330 msg.sendToTarget();
1331
1332 // Wait for the request to complete
1333 synchronized (request) {
1334 while (request.result == null) {
1335 try {
1336 request.wait();
1337 } catch (InterruptedException e) {
1338 // Do nothing, go back and wait until the request is complete
1339 }
1340 }
1341 }
1342 return request.result;
1343 }
1344
1345 /**
1346 * Asynchronous ("fire and forget") version of sendRequest():
1347 * Posts the specified command to be executed on the main thread, and
1348 * returns immediately.
1349 * @see #sendRequest
1350 */
1351 private void sendRequestAsync(int command) {
1352 mMainThreadHandler.sendEmptyMessage(command);
1353 }
1354
1355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 */
1359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 sendRequestAsync(command, argument, null, null);
1361 }
1362
1363 /**
1364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1365 * @see {@link #sendRequest(int,Object)}
1366 */
1367 private void sendRequestAsync(
1368 int command, Object argument, Phone phone, WorkSource workSource) {
1369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001370 Message msg = mMainThreadHandler.obtainMessage(command, request);
1371 msg.sendToTarget();
1372 }
1373
1374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * Initialize the singleton PhoneInterfaceManager instance.
1376 * This is only done once, at startup, from PhoneApp.onCreate().
1377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 synchronized (PhoneInterfaceManager.class) {
1380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 } else {
1383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1384 }
1385 return sInstance;
1386 }
1387 }
1388
1389 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001393 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001394 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001398 mTelephonySharedPreferences =
1399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 publish();
1404 }
1405
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001406 private Phone getDefaultPhone() {
1407 Phone thePhone = getPhone(getDefaultSubscription());
1408 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1409 }
1410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 private void publish() {
1412 if (DBG) log("publish: " + this);
1413
1414 ServiceManager.addService("phone", this);
1415 }
1416
Stuart Scott584921c2015-01-15 17:10:34 -08001417 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001418 if (request.phone != null) {
1419 return request.phone;
1420 } else {
1421 return getPhoneFromSubId(request.subId);
1422 }
1423 }
1424
1425 private Phone getPhoneFromSubId(int subId) {
1426 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1427 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001428 }
1429
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001430 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1431 Phone phone = getPhoneFromRequest(request);
1432 return phone == null ? null :
1433 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1434 }
1435
Wink Saville36469e72014-06-11 15:17:00 -07001436 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001437 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001438 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Naina Nallurid63128d2019-09-17 14:10:30 -07001441 private void sendEraseModemConfig(Phone phone) {
1442 if (phone != null) {
1443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1444 mApp, phone.getSubId(), "eraseModemConfig");
1445 final long identity = Binder.clearCallingIdentity();
1446 try {
1447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
1452 }
1453 }
1454
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("dial: " + number);
1461 // No permission check needed here: This is just a wrapper around the
1462 // ACTION_DIAL intent, which is available to any app since it puts up
1463 // the UI before it does anything.
1464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001465 final long identity = Binder.clearCallingIdentity();
1466 try {
1467 String url = createTelUrl(number);
1468 if (url == null) {
1469 return;
1470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 // PENDING: should we just silently fail if phone is offhook or ringing?
1473 PhoneConstants.State state = mCM.getState(subId);
1474 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1475 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1476 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1477 mApp.startActivity(intent);
1478 }
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 if (DBG) log("call: " + number);
1490
1491 // This is just a wrapper around the ACTION_CALL intent, but we still
1492 // need to do a permission check since we're calling startActivity()
1493 // from the context of the phone app.
1494 enforceCallPermission();
1495
Jordan Liu1617b712019-07-10 15:06:26 -07001496 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 != AppOpsManager.MODE_ALLOWED) {
1498 return;
1499 }
1500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 String url = createTelUrl(number);
1504 if (url == null) {
1505 return;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001508 boolean isValid = false;
1509 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1510 if (slist != null) {
1511 for (SubscriptionInfo subInfoRecord : slist) {
1512 if (subInfoRecord.getSubscriptionId() == subId) {
1513 isValid = true;
1514 break;
1515 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001516 }
Wink Saville08874612014-08-31 19:19:58 -07001517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001518 if (!isValid) {
1519 return;
1520 }
Wink Saville08874612014-08-31 19:19:58 -07001521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1523 intent.putExtra(SUBSCRIPTION_KEY, subId);
1524 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1525 mApp.startActivity(intent);
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
1528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
1540 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001546 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1547 }
1548
1549 /** {@hide} */
1550 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001551 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
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 Saville9de0f752013-10-22 19:04:03 -07001567 /** {@hide} */
1568 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001570 }
1571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1578 checkSimPuk.start();
1579 return checkSimPuk.unlockSim(puk, pin);
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001586 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 * a synchronous one.
1588 */
1589 private static class UnlockSim extends Thread {
1590
1591 private final IccCard mSimCard;
1592
1593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596
1597 // For replies from SimCard interface
1598 private Handler mHandler;
1599
1600 // For async handler to identify request type
1601 private static final int SUPPLY_PIN_COMPLETE = 100;
1602
1603 public UnlockSim(IccCard simCard) {
1604 mSimCard = simCard;
1605 }
1606
1607 @Override
1608 public void run() {
1609 Looper.prepare();
1610 synchronized (UnlockSim.this) {
1611 mHandler = new Handler() {
1612 @Override
1613 public void handleMessage(Message msg) {
1614 AsyncResult ar = (AsyncResult) msg.obj;
1615 switch (msg.what) {
1616 case SUPPLY_PIN_COMPLETE:
1617 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1618 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001619 mRetryCount = msg.arg1;
1620 if (ar.exception != null) {
1621 if (ar.exception instanceof CommandException &&
1622 ((CommandException)(ar.exception)).getCommandError()
1623 == CommandException.Error.PASSWORD_INCORRECT) {
1624 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1625 } else {
1626 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1627 }
1628 } else {
1629 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 mDone = true;
1632 UnlockSim.this.notifyAll();
1633 }
1634 break;
1635 }
1636 }
1637 };
1638 UnlockSim.this.notifyAll();
1639 }
1640 Looper.loop();
1641 }
1642
1643 /*
1644 * Use PIN or PUK to unlock SIM card
1645 *
1646 * If PUK is null, unlock SIM card with PIN
1647 *
1648 * If PUK is not null, unlock SIM card with PUK and set PIN code
1649 */
Wink Saville9de0f752013-10-22 19:04:03 -07001650 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651
1652 while (mHandler == null) {
1653 try {
1654 wait();
1655 } catch (InterruptedException e) {
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1660
1661 if (puk == null) {
1662 mSimCard.supplyPin(pin, callback);
1663 } else {
1664 mSimCard.supplyPuk(puk, pin, callback);
1665 }
1666
1667 while (!mDone) {
1668 try {
1669 Log.d(LOG_TAG, "wait for done");
1670 wait();
1671 } catch (InterruptedException e) {
1672 // Restore the interrupted status
1673 Thread.currentThread().interrupt();
1674 }
1675 }
1676 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001677 int[] resultArray = new int[2];
1678 resultArray[0] = mResult;
1679 resultArray[1] = mRetryCount;
1680 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682 }
1683
1684 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001686
1687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 // No permission check needed here: this call is harmless, and it's
1691 // needed for the ServiceState.requestStateUpdate() call (which is
1692 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.updateServiceLocation();
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001704 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001707 return isRadioOnWithFeature(callingPackage, null);
1708 }
1709
1710
1711 @Override
1712 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1713 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1714 callingFeatureId);
1715 }
1716
1717 @Deprecated
1718 @Override
1719 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1720 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001723 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001724 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1725 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001727 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001728 return false;
1729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 return isRadioOnForSubscriber(subId);
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
1736 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001737 }
1738
1739 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone phone = getPhone(subId);
1743 if (phone != null) {
1744 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1745 } else {
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
1753 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001754 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 final Phone phone = getPhone(subId);
1763 if (phone != null) {
1764 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Wink Saville36469e72014-06-11 15:17:00 -07001769 }
1770
1771 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001772 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
Wink Savilleb564aae2014-10-23 10:18:09 -07001775 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777
1778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 final Phone phone = getPhone(subId);
1781 if (phone == null) {
1782 return false;
1783 }
1784 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1785 toggleRadioOnOffForSubscriber(subId);
1786 }
1787 return true;
1788 } finally {
1789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
Wink Saville36469e72014-06-11 15:17:00 -07001792
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001794 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 /*
1796 * If any of the Radios are available, it will need to be
1797 * shutdown. So return true if any Radio is available.
1798 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 Phone phone = PhoneFactory.getPhone(i);
1803 if (phone != null && phone.isRadioAvailable()) return true;
1804 }
1805 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1806 return false;
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001810 }
1811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 enforceModifyPermission();
1815
1816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1819 logv("Shutting down Phone " + i);
1820 shutdownRadioUsingPhoneId(i);
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001824 }
1825 }
1826
1827 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001828 Phone phone = PhoneFactory.getPhone(phoneId);
1829 if (phone != null && phone.isRadioAvailable()) {
1830 phone.shutdownRadio();
1831 }
1832 }
1833
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1840 if (defaultPhone != null) {
1841 defaultPhone.setRadioPower(turnOn);
1842 return true;
1843 } else {
1844 loge("There's no default phone.");
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001849 }
Wink Saville36469e72014-06-11 15:17:00 -07001850 }
1851
Wink Savilleb564aae2014-10-23 10:18:09 -07001852 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001854
1855 final long identity = Binder.clearCallingIdentity();
1856 try {
1857 final Phone phone = getPhone(subId);
1858 if (phone != null) {
1859 phone.setRadioPower(turnOn);
1860 return true;
1861 } else {
1862 return false;
1863 }
1864 } finally {
1865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 }
1868
Wink Saville36469e72014-06-11 15:17:00 -07001869 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public boolean enableDataConnectivity() {
1872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873
1874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 int subId = mSubscriptionController.getDefaultDataSubId();
1877 final Phone phone = getPhone(subId);
1878 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001879 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 return true;
1881 } else {
1882 return false;
1883 }
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Wink Saville36469e72014-06-11 15:17:00 -07001889 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public boolean disableDataConnectivity() {
1892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 int subId = mSubscriptionController.getDefaultDataSubId();
1897 final Phone phone = getPhone(subId);
1898 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001899 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900 return true;
1901 } else {
1902 return false;
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001910 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 final Phone phone = getPhone(subId);
1914 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001915 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 } else {
1917 return false;
1918 }
1919 } finally {
1920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
1924 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001925 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001926 }
1927
pkanwarae03a6b2016-11-06 20:37:09 -08001928 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929 enforceCallPermission();
1930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1934 return;
1935 }
1936 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1937 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
1940 }
pkanwar32d516d2016-10-14 19:37:38 -07001941 };
1942
Wink Savilleb564aae2014-10-23 10:18:09 -07001943 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1949 return false;
1950 }
1951 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001958 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001959 }
1960
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001961 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
1964 Phone phone = PhoneFactory.getPhone(slotIndex);
1965 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1966 PhoneConstantConversions.convertCallState(phone.getState());
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
1969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001973 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001974 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1975 }
1976
1977 @Override
1978 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 final long identity = Binder.clearCallingIdentity();
1980 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001981 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982 if (phone != null) {
1983 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1984 } else {
1985 return PhoneConstantConversions.convertDataState(
1986 PhoneConstants.DataState.DISCONNECTED);
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001994 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001995 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1996 }
1997
1998 @Override
1999 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 final long identity = Binder.clearCallingIdentity();
2001 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003 if (phone != null) {
2004 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2005 } else {
2006 return TelephonyManager.DATA_ACTIVITY_NONE;
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002014 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002015 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002016 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002017
2018 LocationAccessPolicy.LocationPermissionResult locationResult =
2019 LocationAccessPolicy.checkLocationPermission(mApp,
2020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2021 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002022 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002023 .setCallingPid(Binder.getCallingPid())
2024 .setCallingUid(Binder.getCallingUid())
2025 .setMethod("getCellLocation")
2026 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2027 .build());
2028 switch (locationResult) {
2029 case DENIED_HARD:
2030 throw new SecurityException("Not allowed to access cell location");
2031 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002032 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2033 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 }
2035
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002040 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002041 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Svetoslav64fad262015-04-14 14:35:21 -07002045 }
2046
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002048 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2049 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002050 if (!TextUtils.isEmpty(callingPackage)) {
2051 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2053 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002054 return "";
2055 }
2056 }
2057
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002058 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2059 // registered cell info, so return a NULL country instead.
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002062 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2063 // Get default phone in this case.
2064 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2065 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002066 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002067 // Todo: fix this when we can get the actual cellular network info when the device
2068 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002069 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002070 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2071 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002072 return "";
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 Phone phone = PhoneFactory.getPhone(phoneId);
2075 if (phone != null) {
2076 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002077 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (sst != null) {
2079 LocaleTracker lt = sst.getLocaleTracker();
2080 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002081 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2082 return lt.getCurrentCountry();
2083 } else if (emergencyNumberTracker != null) {
2084 return emergencyNumberTracker.getEmergencyCountryIso();
2085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 }
2087 }
2088 }
2089 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002093 }
2094
2095 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002097 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002098 }
2099
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 mApp.enforceCallingOrSelfPermission(
2103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104
2105 final long identity = Binder.clearCallingIdentity();
2106 try {
2107 final Phone phone = getPhone(subId);
2108 if (phone != null) {
2109 phone.enableLocationUpdates();
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 @Override
2117 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002118 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002119 }
2120
Sanket Padawe356d7632015-06-22 14:03:32 -07002121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 mApp.enforceCallingOrSelfPermission(
2124 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125
2126 final long identity = Binder.clearCallingIdentity();
2127 try {
2128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 phone.disableLocationUpdates();
2131 }
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Nathan Harold31d7ff32018-10-15 20:20:30 -07002137 /**
2138 * Returns the target SDK version number for a given package name.
2139 *
Nathan Haroldec184742019-07-10 17:04:16 -07002140 * This call MUST be invoked before clearing the calling UID.
2141 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 * @return target SDK if the package is found or INT_MAX.
2143 */
2144 private int getTargetSdk(String packageName) {
2145 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002146 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002147 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002148 if (ai != null) return ai.targetSdkVersion;
2149 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002150 loge("Failed to get package info for pkg="
2151 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002152 }
2153 return Integer.MAX_VALUE;
2154 }
2155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 @Override
2157 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002158 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2159 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002160 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002161 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2162 throw new SecurityException(
2163 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2164 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002165
Jordan Liu1617b712019-07-10 15:06:26 -07002166 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2168 return null;
2169 }
Svetoslav64fad262015-04-14 14:35:21 -07002170
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002171 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002173 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
Nathan Haroldf180aac2018-06-01 18:43:55 -07002176 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2177 for (CellInfo ci : info) {
2178 if (ci instanceof CellInfoGsm) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2180 } else if (ci instanceof CellInfoWcdma) {
2181 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002184 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002187 private List<CellInfo> getCachedCellInfo() {
2188 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2189 for (Phone phone : PhoneFactory.getPhones()) {
2190 List<CellInfo> info = phone.getAllCellInfo();
2191 if (info != null) cellInfos.addAll(info);
2192 }
2193 return cellInfos;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195
2196 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002197 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002199 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002200
2201 LocationAccessPolicy.LocationPermissionResult locationResult =
2202 LocationAccessPolicy.checkLocationPermission(mApp,
2203 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2204 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002205 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002209 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002210 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2211 .build());
2212 switch (locationResult) {
2213 case DENIED_HARD:
2214 throw new SecurityException("Not allowed to access cell info");
2215 case DENIED_SOFT:
2216 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 final int targetSdk = getTargetSdk(callingPackage);
2220 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2221 return getCachedCellInfo();
2222 }
2223
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002224 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
2228 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2229 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002230 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002231 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 if (info != null) cellInfos.addAll(info);
2233 }
2234 return cellInfos;
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238 }
2239
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002240 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002241 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2242 String callingFeatureId) {
2243 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2244 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 }
2246
2247 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2249 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002251 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002252 }
2253
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002254 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2255 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002256 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002257 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002258
2259 LocationAccessPolicy.LocationPermissionResult locationResult =
2260 LocationAccessPolicy.checkLocationPermission(mApp,
2261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2262 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002263 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002264 .setCallingPid(Binder.getCallingPid())
2265 .setCallingUid(Binder.getCallingUid())
2266 .setMethod("requestCellInfoUpdate")
2267 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2268 .build());
2269 switch (locationResult) {
2270 case DENIED_HARD:
2271 throw new SecurityException("Not allowed to access cell info");
2272 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002273 try {
2274 cb.onCellInfo(new ArrayList<CellInfo>());
2275 } catch (RemoteException re) {
2276 // Drop without consequences
2277 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002278 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002279 }
2280
Nathan Harolda939a962019-05-09 10:13:47 -07002281
2282 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2284
2285 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2286 }
2287
2288 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002290 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002295 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Shishir Agrawala9f32182016-04-12 12:00:16 -07002301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002302 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 return null;
2306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002308 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002309 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 return null;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 return phone.getImei();
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002319 }
2320
2321 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002322 public String getTypeAllocationCodeForSlot(int slotIndex) {
2323 Phone phone = PhoneFactory.getPhone(slotIndex);
2324 String tac = null;
2325 if (phone != null) {
2326 String imei = phone.getImei();
2327 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2328 }
2329 return tac;
2330 }
2331
2332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002333 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002334 Phone phone = PhoneFactory.getPhone(slotIndex);
2335 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002336 return null;
2337 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002338
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002340 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return phone.getMeid();
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
2350 }
Jack Yu2af8d712017-03-15 17:14:14 -07002351 }
2352
2353 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002354 public String getManufacturerCodeForSlot(int slotIndex) {
2355 Phone phone = PhoneFactory.getPhone(slotIndex);
2356 String manufacturerCode = null;
2357 if (phone != null) {
2358 String meid = phone.getMeid();
2359 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2360 }
2361 return manufacturerCode;
2362 }
2363
2364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002365 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002367 Phone phone = PhoneFactory.getPhone(slotIndex);
2368 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002369 return null;
2370 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002371 int subId = phone.getSubId();
2372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002373 mApp, subId, callingPackage, callingFeatureId,
2374 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 return null;
2376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 return phone.getDeviceSvn();
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002384 }
2385
fionaxu43304da2017-11-27 22:51:16 -08002386 @Override
2387 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
fionaxu43304da2017-11-27 22:51:16 -08002395 }
2396
2397 @Override
2398 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = getPhone(subId);
2402 return phone == null ? null : phone.getCarrierName();
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
fionaxu43304da2017-11-27 22:51:16 -08002406 }
2407
calvinpanffe225e2018-11-01 19:43:06 +08002408 @Override
chen xu0026ca62019-03-06 15:28:50 -08002409 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
2413 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002414 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
2418 }
2419
2420 @Override
chen xu0026ca62019-03-06 15:28:50 -08002421 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002425 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
chen xu651eec72018-11-11 19:03:44 -08002431 @Override
chen xu864e11c2018-12-06 22:10:03 -08002432 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2433 if (!isSubscriptionMccMnc) {
2434 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2435 }
chen xu651eec72018-11-11 19:03:44 -08002436 final Phone phone = PhoneFactory.getPhone(slotIndex);
2437 if (phone == null) {
2438 return TelephonyManager.UNKNOWN_CARRIER_ID;
2439 }
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
2445 }
2446 }
2447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 //
2449 // Internal helper methods.
2450 //
2451
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002452 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2454 *
2455 * @throws SecurityException if the caller does not have the required permission
2456 */
2457 private void enforceModifyPermission() {
2458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2459 }
2460
Shuo Qian3b6ee772019-11-13 17:43:31 -08002461 private void enforceActiveEmergencySessionPermission() {
2462 mApp.enforceCallingOrSelfPermission(
2463 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 /**
2467 * Make sure the caller has the CALL_PHONE permission.
2468 *
2469 * @throws SecurityException if the caller does not have the required permission
2470 */
2471 private void enforceCallPermission() {
2472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2473 }
2474
paulhu5a773602019-08-23 19:17:33 +08002475 private void enforceSettingsPermission() {
2476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002477 }
2478
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 private String createTelUrl(String number) {
2480 if (TextUtils.isEmpty(number)) {
2481 return null;
2482 }
2483
Jake Hambye994d462014-02-03 13:10:13 -08002484 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Ihab Awadf9e92732013-12-05 18:02:52 -08002487 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2489 }
2490
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002491 private static void logv(String msg) {
2492 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2493 }
2494
Ihab Awadf9e92732013-12-05 18:02:52 -08002495 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2497 }
2498
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002499 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002501 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002505 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = PhoneFactory.getPhone(slotIndex);
2509 if (phone == null) {
2510 return PhoneConstants.PHONE_TYPE_NONE;
2511 } else {
2512 return phone.getPhoneType();
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the CDMA ERI icon index to display
2521 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002523 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2524 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2525 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 mApp, subId, callingPackage, callingFeatureId,
2533 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return -1;
2535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 return phone.getCdmaEriIconIndex();
2542 } else {
2543 return -1;
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
2551 * Returns the CDMA ERI icon mode,
2552 * 0 - ON
2553 * 1 - FLASHING
2554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002556 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2557 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2558 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002559 }
2560
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002562 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2563 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002565 mApp, subId, callingPackage, callingFeatureId,
2566 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return -1;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriIconMode();
2575 } else {
2576 return -1;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
2584 * Returns the CDMA ERI text,
2585 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002587 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2588 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2589 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2594 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 mApp, subId, callingPackage, callingFeatureId,
2597 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002598 return null;
2599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 final Phone phone = getPhone(subId);
2604 if (phone != null) {
2605 return phone.getCdmaEriText();
2606 } else {
2607 return null;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
2614 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002615 * Returns the CDMA MDN.
2616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 return phone.getLine1Number();
2627 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002628 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 return null;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002633 }
2634 }
2635
2636 /**
2637 * Returns the CDMA MIN.
2638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002640 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2642 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2648 return phone.getCdmaMin();
2649 } else {
2650 return null;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002654 }
2655 }
2656
Hall Liud892bec2018-11-30 14:51:45 -08002657 @Override
2658 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2659 INumberVerificationCallback callback, String callingPackage) {
2660 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2661 != PERMISSION_GRANTED) {
2662 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2663 }
2664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2665
2666 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2667 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2668 throw new SecurityException("Calling package must be configured in the device config");
2669 }
2670
2671 if (range == null) {
2672 throw new NullPointerException("Range must be non-null");
2673 }
2674
2675 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002676 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002677
2678 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2679 }
2680
Junda Liuca05d5d2014-08-14 22:36:34 -07002681 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 * Returns true if CDMA provisioning needs to run.
2683 */
2684 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002687 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
2693 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002694 * Sets the voice mail number of a given subId.
2695 */
2696 @Override
2697 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002698 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2699 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2704 new Pair<String, String>(alphaTag, number), new Integer(subId));
2705 return success;
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002709 }
2710
Ta-wei Yen87c49842016-05-13 21:19:52 -07002711 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002714 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2715 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002716 if (!TextUtils.equals(callingPackage, systemDialer)) {
2717 throw new SecurityException("caller must be system dialer");
2718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2723 if (phoneAccountHandle == null) {
2724 return null;
2725 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002730 }
2731
2732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002733 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2734 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002737 mApp, subId, callingPackage, callingFeatureId,
2738 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002739 return null;
2740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 final long identity = Binder.clearCallingIdentity();
2743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002748 }
2749
2750 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002751 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2752 VisualVoicemailSmsFilterSettings settings) {
2753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002762 }
2763
2764 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002765 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002771 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002775 }
2776
2777 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002778 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2779 String callingPackage, int subId) {
2780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002785 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002789 }
2790
2791 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002793 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002798 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 }
2803
2804 @Override
2805 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2806 String number, int port, String text, PendingIntent sentIntent) {
2807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002808 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002809 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002810 SmsController smsController = PhoneFactory.getSmsController();
2811 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2812 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002813 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002814
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002815 /**
fionaxu0152e512016-11-14 13:36:14 -08002816 * Sets the voice activation state of a given subId.
2817 */
2818 @Override
2819 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2821 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
2827 phone.setVoiceActivationState(activationState);
2828 } else {
2829 loge("setVoiceActivationState fails with invalid subId: " + subId);
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002833 }
2834 }
2835
2836 /**
2837 * Sets the data activation state of a given subId.
2838 */
2839 @Override
2840 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 final Phone phone = getPhone(subId);
2847 if (phone != null) {
2848 phone.setDataActivationState(activationState);
2849 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002850 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002854 }
2855 }
2856
2857 /**
2858 * Returns the voice activation state of a given subId.
2859 */
2860 @Override
2861 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002862 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
fionaxu0152e512016-11-14 13:36:14 -08002864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 if (phone != null) {
2868 return phone.getVoiceActivationState();
2869 } else {
2870 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002874 }
2875 }
2876
2877 /**
2878 * Returns the data activation state of a given subId.
2879 */
2880 @Override
2881 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002882 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883
fionaxu0152e512016-11-14 13:36:14 -08002884 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (phone != null) {
2888 return phone.getDataActivationState();
2889 } else {
2890 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002894 }
2895 }
2896
2897 /**
Wink Saville36469e72014-06-11 15:17:00 -07002898 * Returns the unread count of voicemails for a subId
2899 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002901 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2902 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002904 mApp, subId, callingPackage, callingFeatureId,
2905 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002906 return 0;
2907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null) {
2912 return phone.getVoiceMessageCount();
2913 } else {
2914 return 0;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
2920
2921 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002922 * returns true, if the device is in a state where both voice and data
2923 * are supported simultaneously. This can change based on location or network condition.
2924 */
2925 @Override
2926 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 final Phone phone = getPhone(subId);
2930 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002934 }
2935
2936 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002937 * Send the dialer code if called from the current default dialer or the caller has
2938 * carrier privilege.
2939 * @param inputCode The dialer code to send
2940 */
2941 @Override
2942 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002945 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2946 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002947 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002949 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
fionaxu235cc5e2017-03-06 22:25:57 -08002958 }
2959
Pengquan Menga1bb6272018-09-06 09:59:22 -07002960 @Override
2961 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002962 if (!isActiveSubscription(subId)) {
2963 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2964 }
2965
Pengquan Menga1bb6272018-09-06 09:59:22 -07002966 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2967 }
2968
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002970 public boolean isInEmergencySmsMode() {
2971 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 for (Phone phone : PhoneFactory.getPhones()) {
2975 if (phone.isInEmergencySmsMode()) {
2976 return true;
2977 }
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 return false;
2983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2987 throws RemoteException {
2988 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002989 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2991 "IMS not available on device.");
2992 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 final long token = Binder.clearCallingIdentity();
2994 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002998 } catch (ImsException e) {
2999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 } finally {
3001 Binder.restoreCallingIdentity(token);
3002 }
3003 }
3004
3005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003006 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3007 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3009 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3010 }
Meng Wangafbc5852019-09-19 17:37:13 -07003011 final long token = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3015 .removeRegistrationCallbackForSubscription(c, subId);
3016 } catch (ImsException e) {
3017 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3018 + "is inactive, ignoring unregister.");
3019 // If the subscription is no longer active, just return, since the callback
3020 // will already have been removed internally.
3021 } finally {
3022 Binder.restoreCallingIdentity(token);
3023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 }
3025
Brad Ebingera34a6c22019-10-22 17:36:18 -07003026 /**
3027 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3028 */
3029 @Override
3030 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3031 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3034 "IMS not available on device.");
3035 }
3036 final long token = Binder.clearCallingIdentity();
3037 try {
3038 Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3041 + subId + "'");
3042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3043 }
3044 phone.getImsRegistrationState(regState -> {
3045 try {
3046 consumer.accept((regState == null)
3047 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3048 } catch (RemoteException e) {
3049 // Ignore if the remote process is no longer available to call back.
3050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3051 }
3052 });
3053 } finally {
3054 Binder.restoreCallingIdentity(token);
3055 }
3056 }
3057
3058 /**
3059 * Get the transport type for the IMS service registration state.
3060 */
3061 @Override
3062 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3063 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3064 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3065 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3066 "IMS not available on device.");
3067 }
3068 final long token = Binder.clearCallingIdentity();
3069 try {
3070 Phone phone = getPhone(subId);
3071 if (phone == null) {
3072 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3073 + subId + "'");
3074 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3075 }
3076 phone.getImsRegistrationTech(regTech -> {
3077 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3078 int regTechConverted = (regTech == null)
3079 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3080 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3081 regTechConverted);
3082 try {
3083 consumer.accept(regTechConverted);
3084 } catch (RemoteException e) {
3085 // Ignore if the remote process is no longer available to call back.
3086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3087 }
3088 });
3089 } finally {
3090 Binder.restoreCallingIdentity(token);
3091 }
3092 }
3093
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003095 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3096 throws RemoteException {
3097 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003098 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3099 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3100 "IMS not available on device.");
3101 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3103 final long token = Binder.clearCallingIdentity();
3104 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (ImsException e) {
3108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 } finally {
3110 Binder.restoreCallingIdentity(token);
3111 }
3112 }
3113
3114 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003115 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3116 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3118 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3119 }
Meng Wangafbc5852019-09-19 17:37:13 -07003120
3121 final long token = Binder.clearCallingIdentity();
3122 try {
3123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3124 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003125 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003126 } catch (ImsException e) {
3127 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3128 + "is inactive, ignoring unregister.");
3129 // If the subscription is no longer active, just return, since the callback
3130 // will already have been removed internally.
3131 } finally {
3132 Binder.restoreCallingIdentity(token);
3133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 }
3135
3136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003137 public boolean isCapable(int subId, int capability, int regTech) {
3138 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3140 final long token = Binder.clearCallingIdentity();
3141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3146 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003147 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003148 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3149 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003150 } finally {
3151 Binder.restoreCallingIdentity(token);
3152 }
3153 }
3154
3155 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003156 public boolean isAvailable(int subId, int capability, int regTech) {
3157 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 final long token = Binder.clearCallingIdentity();
3159 try {
3160 Phone phone = getPhone(subId);
3161 if (phone == null) return false;
3162 return phone.isImsCapabilityAvailable(capability, regTech);
3163 } finally {
3164 Binder.restoreCallingIdentity(token);
3165 }
3166 }
3167
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003168 /**
3169 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3170 * subscription.
3171 * @param subId The subscription to use to check the configuration.
3172 * @param callback The callback that will be used to send the result.
3173 * @param capability The MmTelFeature capability that will be used to send the result.
3174 * @param transportType The transport type of the MmTelFeature capability.
3175 */
3176 @Override
3177 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3178 int transportType) {
3179 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3182 "IMS not available on device.");
3183 }
3184 final long token = Binder.clearCallingIdentity();
3185 try {
3186 int slotId = getSlotIndex(subId);
3187 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3188 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3189 + subId + "'");
3190 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3191 }
3192 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3193 transportType, aBoolean -> {
3194 try {
3195 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3196 } catch (RemoteException e) {
3197 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3198 + "running. Ignore");
3199 }
3200 });
3201 } finally {
3202 Binder.restoreCallingIdentity(token);
3203 }
3204 }
3205
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 @Override
3207 public boolean isAdvancedCallingSettingEnabled(int subId) {
3208 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3210 final long token = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003214 } catch (ImsException e) {
3215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 } finally {
3217 Binder.restoreCallingIdentity(token);
3218 }
3219 }
3220
3221 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003222 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003224 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003230 } catch (ImsException e) {
3231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003238 public boolean isVtSettingEnabled(int subId) {
3239 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003243 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3244 } catch (ImsException e) {
3245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
3249 }
3250
3251 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003252 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003254 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003258 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003259 } catch (ImsException e) {
3260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
3264 }
3265
3266 @Override
3267 public boolean isVoWiFiSettingEnabled(int subId) {
3268 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3269 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 getSlotIndexOrException(subId)).isWfcEnabledByUser();
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
3281 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003282 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003284 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003289 } catch (ImsException e) {
3290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
3294 }
3295
3296 @Override
3297 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3298 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003312 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003314 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003318 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003320 } catch (ImsException e) {
3321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
3325 }
3326
3327 @Override
3328 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3330 "setVoWiFiNonPersistent");
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003335 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003336 } catch (ImsException e) {
3337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
3341 }
3342
3343 @Override
3344 public int getVoWiFiModeSetting(int subId) {
3345 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 } catch (ImsException e) {
3352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
3359 public void setVoWiFiModeSetting(int subId, int mode) {
3360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3361 "setVoWiFiModeSetting");
3362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003365 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003367 } catch (ImsException e) {
3368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public int getVoWiFiRoamingModeSetting(int subId) {
3376 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
3383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
3389 @Override
3390 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3392 "setVoWiFiRoamingModeSetting");
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003398 } catch (ImsException e) {
3399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
3405 @Override
3406 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3408 "setRttCapabilityEnabled");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003412 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3413 } catch (ImsException e) {
3414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
3421 public boolean isTtyOverVolteEnabled(int subId) {
3422 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003426 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003428 } catch (ImsException e) {
3429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 @Override
3436 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3437 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003442 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
3444 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
3450 @Override
3451 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3452 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3453 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003454 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3455 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3456 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 try {
3458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003460 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003462 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3463 + "is inactive, ignoring unregister.");
3464 // If the subscription is no longer active, just return, since the callback will already
3465 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
3469 }
3470
3471 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3473 boolean isProvisioned) {
3474 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3475 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3476 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3477 }
3478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3479 "setProvisioningStatusForCapability");
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3483 Phone phone = getPhone(subId);
3484 if (phone == null) {
3485 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3486 + subId);
3487 return;
3488 }
3489 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3490 return;
3491 }
3492
3493 // this capability requires provisioning, route to the correct API.
3494 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3495 switch (capability) {
3496 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3497 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3498 ims.setVolteProvisioned(isProvisioned);
3499 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3500 ims.setWfcProvisioned(isProvisioned);
3501 }
3502 break;
3503 }
3504 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3505 // There is currently no difference in VT provisioning type.
3506 ims.setVtProvisioned(isProvisioned);
3507 break;
3508 }
3509 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3510 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3511 // change the capability of the feature instead if needed.
3512 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3513 == isProvisioned) {
3514 // No change in provisioning.
3515 return;
3516 }
3517 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3518 try {
3519 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003521 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3522 + ", Exception" + e.getMessage());
3523 }
3524 break;
3525 }
3526 default: {
3527 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3528 + capability + "', which does not require provisioning.");
3529 }
3530 }
3531
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
3537 @Override
3538 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3539 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3540 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3541 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3542 }
3543 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3547 Phone phone = getPhone(subId);
3548 if (phone == null) {
3549 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3550 + subId);
3551 // We will fail with "true" as the provisioning status because this is the default
3552 // if we do not require provisioning.
3553 return true;
3554 }
3555
3556 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3557 return true;
3558 }
3559
3560 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3561 switch (capability) {
3562 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3563 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3564 return ims.isVolteProvisionedOnDevice();
3565 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3566 return ims.isWfcProvisionedOnDevice();
3567 }
3568 // This should never happen, since we are checking tech above to make sure it
3569 // is either LTE or IWLAN.
3570 throw new IllegalArgumentException("Invalid radio technology for voice "
3571 + "capability.");
3572 }
3573 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3574 // There is currently no difference in VT provisioning type.
3575 return ims.isVtProvisionedOnDevice();
3576 }
3577 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3578 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3579 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3580 }
3581 default: {
3582 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3583 + capability + "', which does not require provisioning.");
3584 }
3585 }
3586
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
3591
3592 @Override
3593 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3594 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3595 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3596 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3597 }
3598 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3599 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3600 return (provisionedBits & capability) > 0;
3601 }
3602
3603 @Override
3604 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3605 boolean isProvisioned) {
3606 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3607 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3608 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3609 }
3610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3611 "setProvisioningStatusForCapability");
3612 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3613 // If the current provisioning status for capability already matches isProvisioned,
3614 // do nothing.
3615 if (((provisionedBits & capability) > 0) == isProvisioned) {
3616 return;
3617 }
3618 if (isProvisioned) {
3619 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3620 } else {
3621 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3622 }
3623 }
3624
3625 /**
3626 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3627 * technology. The bitfield should mirror the bitfield defined by
3628 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3629 */
3630 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3631 String key = getMmTelProvisioningKey(subId, tech);
3632 // Default is no capabilities are provisioned.
3633 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3634 }
3635
3636 /**
3637 * Sets the MmTel capability provisioning bitfield (defined by
3638 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3639 * technology specified.
3640 *
3641 * Note: This is a synchronous command and should not be called on UI thread.
3642 */
3643 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3644 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3645 String key = getMmTelProvisioningKey(subId, tech);
3646 editor.putInt(key, newField);
3647 editor.commit();
3648 }
3649
3650 private static String getMmTelProvisioningKey(int subId, int tech) {
3651 // resulting key is provision_ims_mmtel_{subId}_{tech}
3652 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3653 }
3654
3655 /**
3656 * Query CarrierConfig to see if the specified capability requires provisioning for the
3657 * carrier associated with the subscription id.
3658 */
3659 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3660 int capability) {
3661 CarrierConfigManager configManager = new CarrierConfigManager(context);
3662 PersistableBundle c = configManager.getConfigForSubId(subId);
3663 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003664 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3666 false);
3667 boolean requireVoiceVtProvisioning = c.getBoolean(
3668 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3669
3670 // First check to make sure that the capability requires provisioning.
3671 switch (capability) {
3672 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3673 // intentional fallthrough
3674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3675 if (requireVoiceVtProvisioning) {
3676 // Voice and Video requires provisioning
3677 return true;
3678 }
3679 break;
3680 }
3681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3682 if (requireUtProvisioning) {
3683 // UT requires provisioning
3684 return true;
3685 }
3686 break;
3687 }
3688 }
3689 return false;
3690 }
3691
3692 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003693 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3695 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3696 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003697 enforceReadPrivilegedPermission("getImsProvisioningInt");
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003701 int slotId = getSlotIndex(subId);
3702 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3703 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3704 + subId + "' for key:" + key);
3705 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3706 }
3707 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3710 + subId + "' for key:" + key);
3711 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3720 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3721 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003722 enforceReadPrivilegedPermission("getImsProvisioningString");
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 int slotId = getSlotIndex(subId);
3727 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3728 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3729 + subId + "' for key:" + key);
3730 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3731 }
3732 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003733 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3735 + subId + "' for key:" + key);
3736 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
3740 }
3741
3742 @Override
3743 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3745 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3746 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3748 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003752 int slotId = getSlotIndex(subId);
3753 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3754 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3755 + subId + "' for key:" + key);
3756 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3757 }
3758 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003760 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3761 + "' for key:" + key);
3762 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 }
3767
3768 @Override
3769 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3771 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3772 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3774 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003778 int slotId = getSlotIndex(subId);
3779 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3780 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3781 + subId + "' for key:" + key);
3782 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3783 }
3784 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003785 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3787 + "' for key:" + key);
3788 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
3792 }
3793
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 int slotId = SubscriptionManager.getSlotIndex(subId);
3796 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003797 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3798 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 }
3800 return slotId;
3801 }
3802
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003803 private int getSlotIndex(int subId) {
3804 int slotId = SubscriptionManager.getSlotIndex(subId);
3805 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3806 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3807 }
3808 return slotId;
3809 }
3810
Wink Saville36469e72014-06-11 15:17:00 -07003811 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003812 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003813 */
3814 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003815 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3816 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003817 final int targetSdk = getTargetSdk(callingPackage);
3818 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003819 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003820 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003821 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003822 mApp, subId, callingPackage, callingFeatureId,
3823 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3825 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 if (phone != null) {
3831 return phone.getServiceState().getDataNetworkType();
3832 } else {
3833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003838 }
3839
3840 /**
3841 * Returns the data network type
3842 */
3843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003844 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3845 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3846 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003847 }
3848
3849 /**
3850 * Returns the data network type for a subId
3851 */
3852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 mApp, subId, callingPackage, callingFeatureId,
3857 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3859 }
3860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.getServiceState().getDataNetworkType();
3866 } else {
3867 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003872 }
3873
3874 /**
Wink Saville36469e72014-06-11 15:17:00 -07003875 * Returns the Voice network type for a subId
3876 */
3877 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003878 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3879 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003881 mApp, subId, callingPackage, callingFeatureId,
3882 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003883 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3884 }
3885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 final Phone phone = getPhone(subId);
3889 if (phone != null) {
3890 return phone.getServiceState().getVoiceNetworkType();
3891 } else {
3892 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3893 }
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
3898
3899 /**
3900 * @return true if a ICC card is present
3901 */
3902 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003903 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003904 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3905 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003906 }
3907
3908 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003910 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003912 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = PhoneFactory.getPhone(slotIndex);
3916 if (phone != null) {
3917 return phone.getIccCard().hasIccCard();
3918 } else {
3919 return false;
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003924 }
3925
3926 /**
3927 * Return if the current radio is LTE on CDMA. This
3928 * is a tri-state return value as for a period of time
3929 * the mode may be unknown.
3930 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003931 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003933 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003935 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003936 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3937 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3938 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003939 }
3940
Sanket Padawe356d7632015-06-22 14:03:32 -07003941 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003942 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3943 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003945 mApp, subId, callingPackage, callingFeatureId,
3946 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003947 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3948 }
3949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 final Phone phone = getPhone(subId);
3953 if (phone == null) {
3954 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3955 } else {
3956 return phone.getLteOnCdmaMode();
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003960 }
Wink Saville36469e72014-06-11 15:17:00 -07003961 }
3962
Wink Saville36469e72014-06-11 15:17:00 -07003963 /**
3964 * {@hide}
3965 * Returns Default subId, 0 in the case of single standby.
3966 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003968 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003969 }
3970
Shishir Agrawala9f32182016-04-12 12:00:16 -07003971 private int getSlotForDefaultSubscription() {
3972 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3973 }
3974
Wink Savilleb564aae2014-10-23 10:18:09 -07003975 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003976 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003977 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003978
Pengquan Menge92a50d2018-09-21 15:54:48 -07003979 private boolean isActiveSubscription(int subId) {
3980 return mSubscriptionController.isActiveSubId(subId);
3981 }
3982
Ihab Awadf2177b72013-11-25 13:33:23 -08003983 /**
3984 * @see android.telephony.TelephonyManager.WifiCallingChoices
3985 */
3986 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3991 getWhenToMakeWifiCallsDefaultPreference());
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003995 }
3996
3997 /**
3998 * @see android.telephony.TelephonyManager.WifiCallingChoices
3999 */
4000 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004009 }
4010
Sailesh Nepald1e68152013-12-12 19:08:02 -08004011 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004012 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004013 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004014 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004015
Jordan Liu4c733742019-02-28 12:03:40 -08004016 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4017 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4018 if (phoneId == -1) {
4019 throw new IllegalArgumentException("Given slot index: " + slotIndex
4020 + " does not correspond to an active phone");
4021 }
4022 return PhoneFactory.getPhone(phoneId);
4023 }
4024
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004026 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4027 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004031 if (DBG) {
4032 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4033 }
4034 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4035 p2);
4036 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004037
Jordan Liu4c733742019-02-28 12:03:40 -08004038
4039 @Override
4040 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4041 int slotIndex, String callingPackage, String aid, int p2) {
4042 enforceModifyPermission();
4043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4044 if (DBG) {
4045 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4046 }
4047 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4048 callingPackage, aid, p2);
4049 }
4050
4051 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4052 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (TextUtils.equals(ISDR_AID, aid)) {
4056 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4058 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 if (bestComponent == null
4060 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4061 loge("The calling package is not allowed to access ISD-R.");
4062 throw new SecurityException(
4063 "The calling package is not allowed to access ISD-R.");
4064 }
Derek Tan740e1672017-06-27 14:56:27 -07004065 }
Derek Tan740e1672017-06-27 14:56:27 -07004066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004068 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4069 null /* workSource */);
4070 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071 return response;
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004075 }
4076
4077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004078 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004081 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4082 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4083 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004084
Jordan Liu4c733742019-02-28 12:03:40 -08004085 @Override
4086 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4087 enforceModifyPermission();
4088 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4089 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4090 channel);
4091 }
4092
4093 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 if (channel < 0) {
4097 return false;
4098 }
Jordan Liu4c733742019-02-28 12:03:40 -08004099 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4100 null /* workSource */);
4101 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 return success;
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106 }
4107
4108 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004109 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004113 if (DBG) {
4114 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4115 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4116 + p3 + " data=" + data);
4117 }
4118 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4119 command, p1, p2, p3, data);
4120 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004121
Jordan Liu4c733742019-02-28 12:03:40 -08004122 @Override
4123 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4124 int command, int p1, int p2, int p3, String data) {
4125 enforceModifyPermission();
4126 if (DBG) {
4127 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4128 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4129 + p3 + " data=" + data);
4130 }
4131 return iccTransmitApduLogicalChannelWithPermission(
4132 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4133 data);
4134 }
4135
4136 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4137 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004140 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 return "";
4142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004145 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4146 null /* workSource */);
4147 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 // Append the returned status code to the end of the response payload.
4150 String s = Integer.toHexString(
4151 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4152 if (response.payload != null) {
4153 s = IccUtils.bytesToHexString(response.payload) + s;
4154 }
4155 return s;
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004158 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004159 }
Jake Hambye994d462014-02-03 13:10:13 -08004160
Evan Charltonc66da362014-05-16 14:06:40 -07004161 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4163 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4165 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004167 if (DBG) {
4168 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4169 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4170 }
4171 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4172 cla, command, p1, p2, p3, data);
4173 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004174
Jordan Liu4c733742019-02-28 12:03:40 -08004175 @Override
4176 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4177 int command, int p1, int p2, int p3, String data) {
4178 enforceModifyPermission();
4179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4180 if (DBG) {
4181 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4182 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4183 + " data=" + data);
4184 }
4185
4186 return iccTransmitApduBasicChannelWithPermission(
4187 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4188 p2, p3, data);
4189 }
4190
4191 // open APDU basic channel assuming the caller has sufficient permissions
4192 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4193 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4197 && TextUtils.equals(ISDR_AID, data)) {
4198 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4200 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 if (bestComponent == null
4202 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4203 loge("The calling package is not allowed to select ISD-R.");
4204 throw new SecurityException(
4205 "The calling package is not allowed to select ISD-R.");
4206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004207 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004210 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4211 null /* workSource */);
4212 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 // Append the returned status code to the end of the response payload.
4215 String s = Integer.toHexString(
4216 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4217 if (response.payload != null) {
4218 s = IccUtils.bytesToHexString(response.payload) + s;
4219 }
4220 return s;
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004223 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004224 }
4225
4226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004227 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004228 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4230 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 if (DBG) {
4235 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4236 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4237 }
4238
4239 IccIoResult response =
4240 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4241 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4242 subId);
4243
4244 if (DBG) {
4245 log("Exchange SIM_IO [R]" + response);
4246 }
4247
4248 byte[] result = null;
4249 int length = 2;
4250 if (response.payload != null) {
4251 length = 2 + response.payload.length;
4252 result = new byte[length];
4253 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4254 } else {
4255 result = new byte[length];
4256 }
4257
4258 result[length - 1] = (byte) response.sw2;
4259 result[length - 2] = (byte) response.sw1;
4260 return result;
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004263 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004264 }
4265
Nathan Haroldb3014052017-01-25 15:57:32 -08004266 /**
4267 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4268 * on a particular subscription
4269 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004270 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4271 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004273 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004274 return null;
4275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 if (appType != TelephonyManager.APPTYPE_USIM
4280 && appType != TelephonyManager.APPTYPE_SIM) {
4281 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4282 return null;
4283 }
4284 Object response = sendRequest(
4285 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4286 if (response instanceof String[]) {
4287 return (String[]) response;
4288 }
yincheng zhao2737e882019-09-06 17:06:54 -07004289 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004291 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004294 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004295 }
4296
yincheng zhao2737e882019-09-06 17:06:54 -07004297 /**
4298 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4299 * subscription.
4300 *
4301 * @param subId the id of the subscription.
4302 * @param appType the uicc app type, must be USIM or SIM.
4303 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4304 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004305 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004306 * @return number of fplmns that is successfully written to the SIM.
4307 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004308 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4309 String callingFeatureId) {
4310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4311 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004312 if (DBG) logv("no permissions for setForbiddenplmns");
4313 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4314 }
4315 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4316 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4317 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4318 }
4319 if (fplmns == null) {
4320 throw new IllegalArgumentException("Fplmn List provided is null");
4321 }
4322 for (String fplmn : fplmns) {
4323 if (!CellIdentity.isValidPlmn(fplmn)) {
4324 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4325 }
4326 }
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 Object response = sendRequest(
4330 CMD_SET_FORBIDDEN_PLMNS,
4331 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4332 subId);
4333 return (int) response;
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004340 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4342 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 final long identity = Binder.clearCallingIdentity();
4345 try {
4346 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4347 if (response.payload == null) {
4348 return "";
4349 }
Evan Charltonc66da362014-05-16 14:06:40 -07004350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 // Append the returned status code to the end of the response payload.
4352 String s = Integer.toHexString(
4353 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4354 s = IccUtils.bytesToHexString(response.payload) + s;
4355 return s;
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Evan Charltonc66da362014-05-16 14:06:40 -07004359 }
4360
Jake Hambye994d462014-02-03 13:10:13 -08004361 /**
4362 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4363 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4364 *
4365 * @param itemID the ID of the item to read
4366 * @return the NV item as a String, or null on error.
4367 */
4368 @Override
4369 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4372 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373
4374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004377 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4379 return value;
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Jake Hambye994d462014-02-03 13:10:13 -08004383 }
4384
4385 /**
4386 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4387 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4388 *
4389 * @param itemID the ID of the item to read
4390 * @param itemValue the value to write, as a String
4391 * @return true on success; false on any failure
4392 */
4393 @Override
4394 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004395 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398
4399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4402 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004403 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4405 return success;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Jake Hambye994d462014-02-03 13:10:13 -08004409 }
4410
4411 /**
4412 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4413 * Used for device configuration by some CDMA operators.
4414 *
4415 * @param preferredRoamingList byte array containing the new PRL
4416 * @return true on success; false on any failure
4417 */
4418 @Override
4419 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4421 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4426 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4427 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4428 return success;
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
Jake Hambye994d462014-02-03 13:10:13 -08004432 }
4433
4434 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004435 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004436 * Used for device configuration by some CDMA operators.
4437 *
chen xu6dac5ab2018-10-26 17:39:23 -07004438 * @param slotIndex - device slot.
4439 *
Jake Hambye994d462014-02-03 13:10:13 -08004440 * @return true on success; false on any failure
4441 */
4442 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004443 public boolean resetModemConfig(int slotIndex) {
4444 Phone phone = PhoneFactory.getPhone(slotIndex);
4445 if (phone != null) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4447 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448
chen xu6dac5ab2018-10-26 17:39:23 -07004449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4452 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4453 return success;
4454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 }
chen xu6dac5ab2018-10-26 17:39:23 -07004458 return false;
4459 }
4460
4461 /**
4462 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4463 *
4464 * @param slotIndex - device slot.
4465 *
4466 * @return true on success; false on any failure
4467 */
4468 @Override
4469 public boolean rebootModem(int slotIndex) {
4470 Phone phone = PhoneFactory.getPhone(slotIndex);
4471 if (phone != null) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4473 mApp, phone.getSubId(), "rebootModem");
4474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4478 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4479 return success;
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004485 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004486
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004487 public String[] getPcscfAddress(String apnType, String callingPackage,
4488 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004489 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4491 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004492 return new String[0];
4493 }
4494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004497 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Wink Saville36469e72014-06-11 15:17:00 -07004501 }
4502
Brad Ebinger51f743a2017-01-23 13:50:20 -08004503 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004504 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4505 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004506 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004507 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004512 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004513 // may happen if the device does not support IMS.
4514 return;
4515 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004516 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004520 }
4521
4522 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004523 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4524 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004525 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004526 public void disableIms(int slotId) {
4527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004531 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004532 // may happen if the device does not support IMS.
4533 return;
4534 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004535 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004539 }
4540
4541 /**
4542 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4543 * feature or {@link null} if the service is not available. If the feature is available, the
4544 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4545 */
4546 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004547 IImsServiceFeatureCallback callback) {
4548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004552 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004553 // may happen if the device does not support IMS.
4554 return null;
4555 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004556 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004560 }
4561
4562 /**
4563 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4564 * feature during emergency calling or {@link null} if the service is not available. If the
4565 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4566 * listener for feature updates.
4567 */
4568 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004573 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004574 // may happen if the device does not support IMS.
4575 return null;
4576 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004577 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004581 }
4582
Brad Ebinger5f64b052017-12-14 14:26:15 -08004583 /**
4584 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004585 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004586 */
4587 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004592 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004593 // may happen if the device does not support IMS.
4594 return null;
4595 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004596 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004600 }
4601
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 /**
4603 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004604 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004605 */
4606 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004611 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004612 // may happen if the device does not support IMS.
4613 return null;
4614 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004615 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004619 }
4620
Brad Ebinger884c07b2018-02-15 16:17:40 -08004621 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004622 * Sets the ImsService Package Name that Telephony will bind to.
4623 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004624 * @param slotIndex the slot ID that the ImsService should bind for.
4625 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004626 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004627 * @param featureTypes An integer array of feature types associated with a packageName.
4628 * @param packageName The name of the package that the current configuration will be replaced
4629 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004630 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004631 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004632 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4633 int[] featureTypes, String packageName) {
4634 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4635 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4637 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004638 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004642 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004643 // may happen if the device does not support IMS.
4644 return false;
4645 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004646 Map<Integer, String> featureConfig = new HashMap<>();
4647 for (int featureType : featureTypes) {
4648 featureConfig.put(featureType, packageName);
4649 }
4650 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4651 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004655 }
4656
4657 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004658 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004659 *
4660 * @param slotId The slot that the ImsService is associated with.
4661 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4662 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004663 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004664 * @return the package name of the ImsService configuration.
4665 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004666 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4667 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004668 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004669 TelephonyPermissions
4670 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4671 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4672 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 final long identity = Binder.clearCallingIdentity();
4675 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004676 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004677 // may happen if the device does not support IMS.
4678 return "";
4679 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004680 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004681 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4682 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004686 }
4687
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004688 /**
4689 * Get the MmTelFeature state associated with the requested subscription id.
4690 * @param subId The subscription that the MmTelFeature is associated with.
4691 * @param callback A callback with an integer containing the
4692 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4693 */
4694 @Override
4695 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4696 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4697 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4699 "IMS not available on device.");
4700 }
4701 final long token = Binder.clearCallingIdentity();
4702 try {
4703 int slotId = getSlotIndex(subId);
4704 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4705 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4706 + subId + "'");
4707 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4708 }
4709 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4710 try {
4711 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4712 } catch (RemoteException e) {
4713 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4714 + "Ignore");
4715 }
4716 });
4717 } finally {
4718 Binder.restoreCallingIdentity(token);
4719 }
4720 }
4721
Wink Saville36469e72014-06-11 15:17:00 -07004722 public void setImsRegistrationState(boolean registered) {
4723 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724
4725 final long identity = Binder.clearCallingIdentity();
4726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004727 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
Wink Saville36469e72014-06-11 15:17:00 -07004731 }
4732
4733 /**
Stuart Scott54788802015-03-30 13:18:01 -07004734 * Set the network selection mode to automatic.
4735 *
4736 */
4737 @Override
4738 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4740 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741
Pengquan Menge92a50d2018-09-21 15:54:48 -07004742 if (!isActiveSubscription(subId)) {
4743 return;
4744 }
4745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4749 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Stuart Scott54788802015-03-30 13:18:01 -07004753 }
4754
Pengquan Mengea84e042018-09-20 14:57:26 -07004755 /**
4756 * Ask the radio to connect to the input network and change selection mode to manual.
4757 *
4758 * @param subId the id of the subscription.
4759 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4760 * the operator to attach to.
4761 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4762 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4763 * normal network selection next time.
4764 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004765 */
4766 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004767 public boolean setNetworkSelectionModeManual(
4768 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4770 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004771
4772 if (!isActiveSubscription(subId)) {
4773 return false;
4774 }
4775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 final long identity = Binder.clearCallingIdentity();
4777 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004778 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004780 if (DBG) {
4781 log("setNetworkSelectionModeManual: subId: " + subId
4782 + " operator: " + operatorInfo);
4783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004788 }
4789
4790 /**
4791 * Scans for available networks.
4792 */
4793 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004794 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4795 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4797 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004798 LocationAccessPolicy.LocationPermissionResult locationResult =
4799 LocationAccessPolicy.checkLocationPermission(mApp,
4800 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4801 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004802 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004803 .setCallingPid(Binder.getCallingPid())
4804 .setCallingUid(Binder.getCallingUid())
4805 .setMethod("getCellNetworkScanResults")
4806 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4807 .build());
4808 switch (locationResult) {
4809 case DENIED_HARD:
4810 throw new SecurityException("Not allowed to access scan results -- location");
4811 case DENIED_SOFT:
4812 return null;
4813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814
Pengquan Menga1bb6272018-09-06 09:59:22 -07004815 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 try {
4817 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004818 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004823 }
4824
4825 /**
yinxub1bed742017-04-17 11:45:04 -07004826 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004827 *
yinxub1bed742017-04-17 11:45:04 -07004828 * @param subId id of the subscription
4829 * @param request contains the radio access networks with bands/channels to scan
4830 * @param messenger callback messenger for scan results or errors
4831 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004832 * @return the id of the requested scan which can be used to stop the scan.
4833 */
4834 @Override
4835 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004836 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4838 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004839 LocationAccessPolicy.LocationPermissionResult locationResult =
4840 LocationAccessPolicy.checkLocationPermission(mApp,
4841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4842 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004843 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004844 .setCallingPid(Binder.getCallingPid())
4845 .setCallingUid(Binder.getCallingUid())
4846 .setMethod("requestNetworkScan")
4847 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4848 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004849 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004850 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004851 if (e != null) {
4852 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4853 throw e;
4854 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004855 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004856 return TelephonyScanManager.INVALID_SCAN_ID;
4857 }
4858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 }
Hall Liu912dfd32019-04-25 14:02:26 -07004860 int callingUid = Binder.getCallingUid();
4861 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 return mNetworkScanRequestTracker.startNetworkScan(
4865 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004866 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
yinxu504e1392017-04-12 16:03:22 -07004870 }
4871
Hall Liub2ac8ef2019-02-28 15:56:23 -08004872 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004873 NetworkScanRequest request, int subId) {
4874 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4875 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4876 boolean hasNetworkScanPermission =
4877 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4878 == PERMISSION_GRANTED;
4879
4880 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4881 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4882 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004883 }
4884
4885 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4886 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004887 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4888 return new SecurityException("Specific channels must not be"
4889 + " scanned without location access.");
4890 }
4891 }
4892 }
4893
Hall Liub2ac8ef2019-02-28 15:56:23 -08004894 return null;
4895 }
4896
yinxu504e1392017-04-12 16:03:22 -07004897 /**
4898 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004899 *
4900 * @param subId id of the subscription
4901 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004902 */
4903 @Override
4904 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4906 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907
Hall Liu912dfd32019-04-25 14:02:26 -07004908 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004911 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
yinxu504e1392017-04-12 16:03:22 -07004915 }
4916
4917 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004918 * Get the calculated preferred network type.
4919 * Used for debugging incorrect network type.
4920 *
4921 * @return the preferred network type, defined in RILConstants.java.
4922 */
4923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004924 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004925 final Phone defaultPhone = getDefaultPhone();
4926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004927 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004928 return RILConstants.PREFERRED_NETWORK_MODE;
4929 }
4930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
Junda Liu84d15a22014-07-02 11:21:04 -07004938 }
4939
4940 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004941 * Get the preferred network type.
4942 * Used for device configuration by some CDMA operators.
4943 *
4944 * @return the preferred network type, defined in RILConstants.java.
4945 */
4946 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004947 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004948 TelephonyPermissions
4949 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4950 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951
4952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 if (DBG) log("getPreferredNetworkType");
4955 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4956 int networkType = (result != null ? result[0] : -1);
4957 if (DBG) log("getPreferredNetworkType: " + networkType);
4958 return networkType;
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004962 }
4963
4964 /**
4965 * Set the preferred network type.
4966 * Used for device configuration by some CDMA operators.
4967 *
4968 * @param networkType the preferred network type, defined in RILConstants.java.
4969 * @return true on success; false on any failure.
4970 */
4971 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004972 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4979 Boolean success = (Boolean) sendRequest(
4980 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4981 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4982 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004983 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4985 }
4986 return success;
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004989 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004990 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004991
4992 /**
Miaoa84611c2019-03-15 09:21:10 +08004993 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004994 *
Miaoa84611c2019-03-15 09:21:10 +08004995 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004996 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004997 * @hide
4998 */
4999 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005000 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 try {
Miaoa84611c2019-03-15 09:21:10 +08005005 if (phone != null) {
5006 return phone.hasMatchedTetherApnSetting();
5007 } else {
5008 return false;
5009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005012 }
Junda Liu475951f2014-11-07 16:45:03 -08005013 }
5014
5015 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005016 * Set mobile data enabled
5017 * Used by the user through settings etc to turn on/off mobile data
5018 *
5019 * @param enable {@code true} turn turn data on, else {@code false}
5020 */
5021 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005022 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5024 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 int phoneId = mSubscriptionController.getPhoneId(subId);
5029 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5030 Phone phone = PhoneFactory.getPhone(phoneId);
5031 if (phone != null) {
5032 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005033 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005035 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 }
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005039 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005040 }
5041
5042 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005043 * Get the user enabled state of Mobile Data.
5044 *
5045 * TODO: remove and use isUserDataEnabled.
5046 * This can't be removed now because some vendor codes
5047 * calls through ITelephony directly while they should
5048 * use TelephonyManager.
5049 *
5050 * @return true on enabled
5051 */
5052 @Override
5053 public boolean getDataEnabled(int subId) {
5054 return isUserDataEnabled(subId);
5055 }
5056
5057 /**
5058 * Get whether mobile data is enabled per user setting.
5059 *
5060 * There are other factors deciding whether mobile data is actually enabled, but they are
5061 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005062 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005063 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005064 *
5065 * @return {@code true} if data is enabled else {@code false}
5066 */
5067 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005068 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005069 try {
5070 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5071 null);
5072 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5074 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076
5077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 int phoneId = mSubscriptionController.getPhoneId(subId);
5080 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5081 Phone phone = PhoneFactory.getPhone(phoneId);
5082 if (phone != null) {
5083 boolean retVal = phone.isUserDataEnabled();
5084 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5085 return retVal;
5086 } else {
5087 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5088 return false;
5089 }
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005092 }
5093 }
5094
5095 /**
5096 * Get whether mobile data is enabled.
5097 *
5098 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5099 * whether mobile data is actually enabled.
5100 *
5101 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5102 *
5103 * @return {@code true} if data is enabled else {@code false}
5104 */
5105 @Override
5106 public boolean isDataEnabled(int subId) {
5107 try {
5108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5109 null);
5110 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5112 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 int phoneId = mSubscriptionController.getPhoneId(subId);
5118 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5119 Phone phone = PhoneFactory.getPhone(phoneId);
5120 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005121 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5123 return retVal;
5124 } else {
5125 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5126 return false;
5127 }
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005130 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005131 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005132
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005133 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5134 Phone phone) {
5135 //load access rules from carrier configs, and check those as well: b/139133814
5136 SubscriptionController subController = SubscriptionController.getInstance();
5137 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5138 || subController == null) return privilegeFromSim;
5139
5140 int uid = Binder.getCallingUid();
5141 PackageManager pkgMgr = phone.getContext().getPackageManager();
5142 String[] packages = pkgMgr.getPackagesForUid(uid);
5143
5144 final long identity = Binder.clearCallingIdentity();
5145 try {
5146 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5147 SubscriptionManager subManager = (SubscriptionManager)
5148 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5149 for (String pkg : packages) {
5150 if (subManager.canManageSubscription(subInfo, pkg)) {
5151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5152 }
5153 }
5154 return privilegeFromSim;
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
5160 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5161 String pkgName) {
5162 //load access rules from carrier configs, and check those as well: b/139133814
5163 SubscriptionController subController = SubscriptionController.getInstance();
5164 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5165 || subController == null) return privilegeFromSim;
5166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5170 SubscriptionManager subManager = (SubscriptionManager)
5171 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5172 return subManager.canManageSubscription(subInfo, pkgName)
5173 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005179 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005180 public int getCarrierPrivilegeStatus(int subId) {
5181 final Phone phone = getPhone(subId);
5182 if (phone == null) {
5183 loge("getCarrierPrivilegeStatus: Invalid subId");
5184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5185 }
5186 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005187 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005188 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5190 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005191
5192 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5193 card.getCarrierPrivilegeStatusForCurrentTransaction(
5194 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005195 }
Junda Liu29340342014-07-10 15:23:27 -07005196
5197 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005199 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005200 final Phone phone = getPhone(subId);
5201 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005202 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005203 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5204 }
5205 UiccProfile profile =
5206 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5207 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005208 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005209 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5210 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005211 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005212 profile.getCarrierPrivilegeStatusForUid(
5213 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 }
5215
5216 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005217 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5218 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005219 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005220 }
5221
5222 int phoneId = SubscriptionManager.getPhoneId(subId);
5223 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005224 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005225 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005226 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5227 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005228 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5229 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5230 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005231 }
5232
5233 @Override
5234 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005235 if (TextUtils.isEmpty(pkgName))
5236 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005237 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5238 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5239 UiccCard card = UiccController.getInstance().getUiccCard(i);
5240 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005241 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005242 continue;
5243 }
5244
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005245 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5246 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5247 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005248 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5249 break;
5250 }
5251 }
5252
5253 return result;
Junda Liu29340342014-07-10 15:23:27 -07005254 }
Derek Tan89e89d42014-07-08 17:00:10 -07005255
5256 @Override
Junda Liue64de782015-04-16 17:19:16 -07005257 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5258 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5259 loge("phoneId " + phoneId + " is not valid.");
5260 return null;
5261 }
5262 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005263 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005264 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005265 return null ;
5266 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005267 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005268 }
5269
Amith Yamasani6e118872016-02-19 12:53:51 -08005270 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005271 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005272 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005273 List<String> privilegedPackages = new ArrayList<>();
5274 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005275 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5276 // has UICC in that slot.
5277 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005278 if (card.hasCarrierPrivilegeRules()) {
5279 if (packages == null) {
5280 // Only check packages in user 0 for now
5281 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005282 PackageManager.MATCH_DISABLED_COMPONENTS
5283 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005284 | PackageManager.GET_SIGNING_CERTIFICATES,
5285 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005286 }
5287 for (int p = packages.size() - 1; p >= 0; p--) {
5288 PackageInfo pkgInfo = packages.get(p);
5289 if (pkgInfo != null && pkgInfo.packageName != null
5290 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005291 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005292 privilegedPackages.add(pkgInfo.packageName);
5293 }
5294 }
5295 }
5296 }
5297 return privilegedPackages;
5298 }
5299
chen xuf7e9fe82019-05-09 19:31:02 -07005300 @Override
5301 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005302 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5303
5304 final long identity = Binder.clearCallingIdentity();
5305
chen xuf7e9fe82019-05-09 19:31:02 -07005306 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005307 try {
5308 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5309 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5310 }
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005313 }
5314 return privilegedPackages;
5315 }
5316
Wink Savilleb564aae2014-10-23 10:18:09 -07005317 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005318 final Phone phone = getPhone(subId);
5319 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005320 if (card == null) {
5321 loge("getIccId: No UICC");
5322 return null;
5323 }
5324 String iccId = card.getIccId();
5325 if (TextUtils.isEmpty(iccId)) {
5326 loge("getIccId: ICC ID is null or empty.");
5327 return null;
5328 }
5329 return iccId;
5330 }
5331
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005332 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005333 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5334 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005335 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005336 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 final String iccId = getIccId(subId);
5341 final Phone phone = getPhone(subId);
5342 if (phone == null) {
5343 return false;
5344 }
5345 final String subscriberId = phone.getSubscriberId();
5346
5347 if (DBG_MERGE) {
5348 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5349 + subscriberId + " to " + number);
5350 }
5351
5352 if (TextUtils.isEmpty(iccId)) {
5353 return false;
5354 }
5355
5356 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5357
5358 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5359 if (alphaTag == null) {
5360 editor.remove(alphaTagPrefKey);
5361 } else {
5362 editor.putString(alphaTagPrefKey, alphaTag);
5363 }
5364
5365 // Record both the line number and IMSI for this ICCID, since we need to
5366 // track all merged IMSIs based on line number
5367 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5368 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5369 if (number == null) {
5370 editor.remove(numberPrefKey);
5371 editor.remove(subscriberPrefKey);
5372 } else {
5373 editor.putString(numberPrefKey, number);
5374 editor.putString(subscriberPrefKey, subscriberId);
5375 }
5376
5377 editor.commit();
5378 return true;
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005381 }
Derek Tan7226c842014-07-02 17:42:23 -07005382 }
5383
5384 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005385 public String getLine1NumberForDisplay(int subId, String callingPackage,
5386 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005387 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005389 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005390 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005391 return null;
5392 }
Derek Tan97ebb422014-09-05 16:55:38 -07005393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 String iccId = getIccId(subId);
5397 if (iccId != null) {
5398 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5399 if (DBG_MERGE) {
5400 log("getLine1NumberForDisplay returning "
5401 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5402 }
5403 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5406 return null;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005409 }
Derek Tan7226c842014-07-02 17:42:23 -07005410 }
5411
5412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005413 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5414 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005416 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005417 return null;
5418 }
Derek Tan97ebb422014-09-05 16:55:38 -07005419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 String iccId = getIccId(subId);
5423 if (iccId != null) {
5424 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5425 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5426 }
5427 return null;
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005430 }
Derek Tan7226c842014-07-02 17:42:23 -07005431 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005432
5433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005434 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5435 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005436 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5437 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005439 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005440 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005441 return null;
5442 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005443
Jordan Liub49b04b2019-05-06 14:45:15 -07005444 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5445 // the process, where TelephonyManager was instantiated.
5446 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005447 final long identity = Binder.clearCallingIdentity();
5448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005449 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final TelephonyManager tele = TelephonyManager.from(context);
5451 final SubscriptionManager sub = SubscriptionManager.from(context);
5452
5453 // Figure out what subscribers are currently active
5454 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
Jordan Liub49b04b2019-05-06 14:45:15 -07005456 // Only consider subs which match the current subId
5457 // This logic can be simplified. See b/131189269 for progress.
5458 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005459 activeSubscriberIds.add(tele.getSubscriberId(subId));
5460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461
5462 // First pass, find a number override for an active subscriber
5463 String mergeNumber = null;
5464 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5465 for (String key : prefs.keySet()) {
5466 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5467 final String subscriberId = (String) prefs.get(key);
5468 if (activeSubscriberIds.contains(subscriberId)) {
5469 final String iccId = key.substring(
5470 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5471 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5472 mergeNumber = (String) prefs.get(numberKey);
5473 if (DBG_MERGE) {
5474 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5475 + " for active subscriber " + subscriberId);
5476 }
5477 if (!TextUtils.isEmpty(mergeNumber)) {
5478 break;
5479 }
5480 }
5481 }
5482 }
5483
5484 // Shortcut when no active merged subscribers
5485 if (TextUtils.isEmpty(mergeNumber)) {
5486 return null;
5487 }
5488
5489 // Second pass, find all subscribers under that line override
5490 final ArraySet<String> result = new ArraySet<>();
5491 for (String key : prefs.keySet()) {
5492 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5493 final String number = (String) prefs.get(key);
5494 if (mergeNumber.equals(number)) {
5495 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5496 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5497 final String subscriberId = (String) prefs.get(subscriberKey);
5498 if (!TextUtils.isEmpty(subscriberId)) {
5499 result.add(subscriberId);
5500 }
5501 }
5502 }
5503 }
5504
5505 final String[] resultArray = result.toArray(new String[result.size()]);
5506 Arrays.sort(resultArray);
5507 if (DBG_MERGE) {
5508 Slog.d(LOG_TAG,
5509 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5510 }
5511 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005514 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005515 }
5516
5517 @Override
zoey chen38003472019-12-13 17:16:31 +08005518 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5519 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 final TelephonyManager telephonyManager = mApp.getSystemService(
5524 TelephonyManager.class);
5525 String subscriberId = telephonyManager.getSubscriberId(subId);
5526 if (subscriberId == null) {
5527 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005528 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005529 + subId);
5530 }
5531 return null;
5532 }
5533
5534 final SubscriptionInfo info = SubscriptionController.getInstance()
5535 .getSubscriptionInfo(subId);
5536 final ParcelUuid groupUuid = info.getGroupUuid();
5537 // If it doesn't belong to any group, return just subscriberId of itself.
5538 if (groupUuid == null) {
5539 return new String[]{subscriberId};
5540 }
5541
5542 // Get all subscriberIds from the group.
5543 final List<String> mergedSubscriberIds = new ArrayList<>();
5544 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005545 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5546 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005547 for (SubscriptionInfo subInfo : groupInfos) {
5548 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5549 if (subscriberId != null) {
5550 mergedSubscriberIds.add(subscriberId);
5551 }
5552 }
5553
5554 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557
5558 }
5559 }
5560
5561 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005562 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005563 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005564 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 final Phone phone = getPhone(subId);
5569 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005573 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005574
5575 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005576 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005577 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5578 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005579 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5580 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581
5582 final long identity = Binder.clearCallingIdentity();
5583 try {
5584 final Phone phone = getPhone(subId);
5585 if (phone == null) {
5586 return false;
5587 }
5588 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5589 cdmaNonRoamingList);
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005592 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005593 }
5594
5595 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005596 @Deprecated
5597 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5598 enforceModifyPermission();
5599
5600 int returnValue = 0;
5601 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005602 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005603 if(result.exception == null) {
5604 if (result.result != null) {
5605 byte[] responseData = (byte[])(result.result);
5606 if(responseData.length > oemResp.length) {
5607 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5608 responseData.length + "bytes. Buffer Size is " +
5609 oemResp.length + "bytes.");
5610 }
5611 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5612 returnValue = responseData.length;
5613 }
5614 } else {
5615 CommandException ex = (CommandException) result.exception;
5616 returnValue = ex.getCommandError().ordinal();
5617 if(returnValue > 0) returnValue *= -1;
5618 }
5619 } catch (RuntimeException e) {
5620 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5621 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5622 if(returnValue > 0) returnValue *= -1;
5623 }
5624
5625 return returnValue;
5626 }
5627
5628 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005629 public void setRadioCapability(RadioAccessFamily[] rafs) {
5630 try {
5631 ProxyController.getInstance().setRadioCapability(rafs);
5632 } catch (RuntimeException e) {
5633 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5634 }
5635 }
5636
5637 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005638 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005639 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005640 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005641 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005642 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 final long identity = Binder.clearCallingIdentity();
5645 try {
chen xub97461a2018-10-26 14:17:57 -07005646 TelephonyPermissions
5647 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5648 mApp, phone.getSubId(), "getRadioAccessFamily");
5649 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
chen xub97461a2018-10-26 14:17:57 -07005653 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005654 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005655
5656 @Override
5657 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005658 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005659 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005663 ImsManager.getInstance(defaultPhone.getContext(),
5664 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005668 }
5669
5670 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005671 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005672 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5674 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005675 return false;
5676 }
Svet Ganovb320e182015-04-16 12:30:10 -07005677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 // Check the user preference and the system-level IMS setting. Even if the user has
5681 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5682 // In the long run, we may instead need to check if there exists a connection service
5683 // which can support video calling.
5684 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005685 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 return imsManager.isVtEnabledByPlatform()
5687 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5688 && imsManager.isVtEnabledByUser();
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005692 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005693
Andrew Leea1239f22015-03-02 17:44:07 -08005694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005695 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5696 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005698 mApp, subId, callingPackage, callingFeatureId,
5699 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 return false;
5701 }
5702
5703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 CarrierConfigManager configManager =
5706 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Andrew Leea1239f22015-03-02 17:44:07 -08005712 }
5713
5714 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005715 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005717 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 return false;
5719 }
5720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 CarrierConfigManager configManager =
5724 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Andrew Leea1239f22015-03-02 17:44:07 -08005730 }
5731
Andrew Lee9431b832015-03-09 18:46:45 -07005732 @Override
5733 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005734 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005735 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005736 }
5737
5738 @Override
5739 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 final long identity = Binder.clearCallingIdentity();
5741 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005742 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Andrew Lee9431b832015-03-09 18:46:45 -07005746 }
5747
Hall Liuf6668912018-10-31 17:05:23 -07005748 /**
5749 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5750 * support for the feature and device firmware support.
5751 *
5752 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5753 */
5754 @Override
5755 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005757 final Phone phone = getPhone(subscriptionId);
5758 if (phone == null) {
5759 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5760 return false;
5761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005763 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5765 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005766 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 return isCarrierSupported && isDeviceSupported;
5768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Hall Liu98187582018-01-22 19:15:32 -08005771 }
5772
Hall Liuf6668912018-10-31 17:05:23 -07005773 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005774 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5775 * RTT setting, will return true if the device and carrier both support RTT.
5776 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005777 */
5778 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779 final long identity = Binder.clearCallingIdentity();
5780 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005781 boolean isRttSupported = isRttSupported(subscriptionId);
5782 boolean isUserRttSettingOn = Settings.Secure.getInt(
5783 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5784 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5785 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5786 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005790 }
5791
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005792 @Deprecated
5793 @Override
5794 public String getDeviceId(String callingPackage) {
5795 return getDeviceIdWithFeature(callingPackage, null);
5796 }
5797
Sanket Padawe7310cc72015-01-14 09:53:20 -08005798 /**
5799 * Returns the unique device ID of phone, for example, the IMEI for
5800 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5801 *
5802 * <p>Requires Permission:
5803 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5804 */
5805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005807 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005808 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005809 return null;
5810 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005811 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005812 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005813 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005814 return null;
5815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 return phone.getDeviceId();
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005823 }
5824
Ping Sunc67b7c22016-03-02 19:16:45 +08005825 /**
5826 * {@hide}
5827 * Returns the IMS Registration Status on a particular subid
5828 *
5829 * @param subId
5830 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005831 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005832 Phone phone = getPhone(subId);
5833 if (phone != null) {
5834 return phone.isImsRegistered();
5835 } else {
5836 return false;
5837 }
5838 }
5839
Santos Cordon7a1885b2015-02-03 11:15:19 -08005840 @Override
5841 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005848 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005849
Tyler Gunnf70ed162019-04-03 15:28:53 -07005850 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005851 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005852 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005854 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005855 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5856 }
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
5864
5865 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005866 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 Phone phone = getPhone(subscriptionId);
5870 if (phone == null) {
5871 return null;
5872 }
5873 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
5877 }
5878
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005879 /**
5880 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005881 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005882 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 Phone phone = getPhone(subId);
5886 if (phone != null) {
5887 return phone.isWifiCallingEnabled();
5888 } else {
5889 return false;
5890 }
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005893 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005894 }
5895
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005896 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005897 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005898 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005899 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 Phone phone = getPhone(subId);
5903 if (phone != null) {
5904 return phone.isVideoEnabled();
5905 } else {
5906 return false;
5907 }
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005910 }
5911 }
5912
5913 /**
5914 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5915 * defined in {@link ImsRegistrationImplBase}.
5916 */
5917 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 Phone phone = getPhone(subId);
5921 if (phone != null) {
5922 return phone.getImsRegistrationTech();
5923 } else {
5924 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5925 }
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005928 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005929 }
5930
Stuart Scott8eef64f2015-04-08 15:13:54 -07005931 @Override
5932 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005933 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005934 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5935 return;
5936 }
5937
Svet Ganovcc087f82015-05-12 20:35:54 -07005938 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005939
Svet Ganovcc087f82015-05-12 20:35:54 -07005940 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005941 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5942 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005943 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005944 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005945 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005946 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5947 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005948 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005949 // There has been issues when Sms raw table somehow stores orphan
5950 // fragments. They lead to garbled message when new fragments come
5951 // in and combined with those stale ones. In case this happens again,
5952 // user can reset all network settings which will clean up this table.
5953 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005954 // Clean up IMS settings as well here.
5955 int slotId = getSlotIndex(subId);
5956 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5957 ImsManager.getInstance(mApp, slotId).factoryReset();
5958 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005959
5960 // Erase modem config if erase modem on network setting is enabled.
5961 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5962 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5963 if (configValue != null && Boolean.parseBoolean(configValue)) {
5964 sendEraseModemConfig(getDefaultPhone());
5965 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005966 } finally {
5967 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005968 }
5969 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005970
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005971 private void cleanUpSmsRawTable(Context context) {
5972 ContentResolver resolver = context.getContentResolver();
5973 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5974 resolver.delete(uri, null, null);
5975 }
5976
Narayan Kamath1c496c22015-04-16 14:40:19 +01005977 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005978 public String getSimLocaleForSubscriber(int subId) {
5979 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5980 final Phone phone = getPhone(subId);
5981 if (phone == null) {
5982 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005983 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 final long identity = Binder.clearCallingIdentity();
5986 try {
chen xu5d3637b2019-01-21 23:31:38 -08005987 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005988 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005989 if (info == null) {
5990 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5991 return null;
5992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 // Try and fetch the locale from the carrier properties or from the SIM language
5994 // preferences (EF-PL and EF-LI)...
5995 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005997 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5998 if (localeFromDefaultSim != null) {
5999 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6000 if (DBG) log("Using locale from subId: " + subId + " locale: "
6001 + localeFromDefaultSim);
6002 return localeFromDefaultSim.toLanguageTag();
6003 } else {
6004 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 }
6006 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 // The SIM language preferences only store a language (e.g. fr = French), not an
6009 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6010 // the SIM and carrier preferences does not include a country we add the country
6011 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006012 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006014 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 return mccLocale.toLanguageTag();
6016 }
6017
6018 if (DBG) log("No locale found - returning null");
6019 return null;
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006023 }
6024
6025 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006026 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6027 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006028 }
6029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 /**
6031 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6032 */
6033 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006034 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6035 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006036 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006037
Chenjie Yu1ba97252018-01-11 18:16:20 -08006038 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006039 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006040
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006041 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006042 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6043 * representing the state of the modem.
6044 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006045 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6046 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006047 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006048 */
6049 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006050 public void requestModemActivityInfo(ResultReceiver result) {
6051 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
6056 ModemActivityInfo ret = null;
6057 synchronized (mLastModemActivityInfo) {
6058 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6059 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006060 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006061 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006063 int[] txTimeMs = info.getTransmitTimeMillis();
6064 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006066 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 }
6068 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006069 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6070 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 mLastModemActivityInfo.setIdleTimeMillis(
6072 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006073 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6074 mLastModemActivityInfo.setReceiveTimeMillis(
6075 info.getReceiveTimeMillis() + mLastModemActivityInfo
6076 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006077 }
Chen Xud78231e2019-09-10 18:49:52 -07006078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6080 mLastModemActivityInfo.getSleepTimeMillis(),
6081 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006082 mLastModemActivityInfo.getTransmitTimeMillis(),
6083 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 Bundle bundle = new Bundle();
6086 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6087 result.send(0, bundle);
6088 } finally {
6089 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006090 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006091 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006092
Siddharth Rayb8114062018-06-17 15:02:38 -07006093 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6094 // less than total activity duration.
6095 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6096 if (info == null) {
6097 return false;
6098 }
6099 int activityDurationMs =
6100 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6101 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006102 int[] txTimeMs = info.getTransmitTimeMillis();
6103 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6104 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006105 }
6106 return (info.isValid()
6107 && (info.getSleepTimeMillis() <= activityDurationMs)
6108 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006109 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006110 && (totalTxTimeMs <= activityDurationMs));
6111 }
6112
Jack Yu85bd38a2015-11-09 11:34:32 -08006113 /**
6114 * {@hide}
6115 * Returns the service state information on specified subscription.
6116 */
6117 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006118 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6119 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006121 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006122 return null;
6123 }
6124
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6126 LocationAccessPolicy.checkLocationPermission(mApp,
6127 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6128 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006129 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006130 .setCallingPid(Binder.getCallingPid())
6131 .setCallingUid(Binder.getCallingUid())
6132 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006133 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006134 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6135 .build());
6136
6137 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6138 LocationAccessPolicy.checkLocationPermission(mApp,
6139 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6140 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006141 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006142 .setCallingPid(Binder.getCallingPid())
6143 .setCallingUid(Binder.getCallingUid())
6144 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006145 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006146 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6147 .build());
6148 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6149 boolean hasFinePermission =
6150 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6151 boolean hasCoarsePermission =
6152 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 final long identity = Binder.clearCallingIdentity();
6155 try {
6156 final Phone phone = getPhone(subId);
6157 if (phone == null) {
6158 return null;
6159 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006160
Hall Liuf19c44f2018-11-27 14:38:17 -08006161 ServiceState ss = phone.getServiceState();
6162
6163 // Scrub out the location info in ServiceState depending on what level of access
6164 // the caller has.
6165 if (hasFinePermission) return ss;
6166 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6167 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006171 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006172
6173 /**
6174 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6175 *
6176 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6177 * voicemail ringtone.
6178 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6179 * PhoneAccount.
6180 */
6181 @Override
6182 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6186 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006187 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006194 }
6195
6196 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006197 * Sets the per-account voicemail ringtone.
6198 *
6199 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6200 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6201 *
6202 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6203 * voicemail ringtone.
6204 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6205 * PhoneAccount.
6206 */
6207 @Override
6208 public void setVoicemailRingtoneUri(String callingPackage,
6209 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006210 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006211 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006212 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6213 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6215 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6216 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218
6219 final long identity = Binder.clearCallingIdentity();
6220 try {
6221 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6222 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006223 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 }
6225 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006228 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006229 }
6230
6231 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006232 * Returns whether vibration is set for voicemail notification in Phone settings.
6233 *
6234 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6235 * voicemail vibration setting.
6236 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6237 */
6238 @Override
6239 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6243 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006244 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006251 }
6252
Youhan Wange64578a2016-05-02 15:32:42 -07006253 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006254 * Sets the per-account voicemail vibration.
6255 *
6256 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6257 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6258 *
6259 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6260 * voicemail vibration setting.
6261 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6262 * specific PhoneAccount.
6263 */
6264 @Override
6265 public void setVoicemailVibrationEnabled(String callingPackage,
6266 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006267 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006268 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006269 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6270 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6272 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6273 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006274 }
6275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 final long identity = Binder.clearCallingIdentity();
6277 try {
6278 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6279 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006280 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 }
6282 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6283 } finally {
6284 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006285 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006286 }
6287
6288 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006289 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6290 *
6291 * @throws SecurityException if the caller does not have the required permission
6292 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006293 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006294 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006295 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006296 }
6297
6298 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006299 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6300 * permission.
6301 *
6302 * @throws SecurityException if the caller does not have the required permission
6303 */
6304 private void enforceSendSmsPermission() {
6305 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6306 }
6307
6308 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006309 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006310 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006311 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006312 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006313 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 final long identity = Binder.clearCallingIdentity();
6315 try {
6316 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006317 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 if (componentName == null) {
6319 throw new SecurityException(
6320 "Caller not current active visual voicemail package[null]");
6321 }
6322 String vvmPackage = componentName.getPackageName();
6323 if (!callingPackage.equals(vvmPackage)) {
6324 throw new SecurityException("Caller not current active visual voicemail package["
6325 + vvmPackage + "]");
6326 }
6327 } finally {
6328 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006329 }
6330 }
6331
6332 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006333 * Return the application ID for the app type.
6334 *
6335 * @param subId the subscription ID that this request applies to.
6336 * @param appType the uicc app type.
6337 * @return Application ID for specificied app type, or null if no uicc.
6338 */
6339 @Override
6340 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006341 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006342 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343
6344 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006345 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 if (phone == null) {
6347 return null;
6348 }
6349 String aid = null;
6350 try {
6351 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6352 .getApplicationByType(appType).getAid();
6353 } catch (Exception e) {
6354 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6355 }
6356 return aid;
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006359 }
Youhan Wange64578a2016-05-02 15:32:42 -07006360 }
6361
Youhan Wang4001d252016-05-11 10:29:41 -07006362 /**
6363 * Return the Electronic Serial Number.
6364 *
6365 * @param subId the subscription ID that this request applies to.
6366 * @return ESN or null if error.
6367 */
6368 @Override
6369 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006370 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006371 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372
6373 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006374 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 if (phone == null) {
6376 return null;
6377 }
6378 String esn = null;
6379 try {
6380 esn = phone.getEsn();
6381 } catch (Exception e) {
6382 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6383 }
6384 return esn;
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006387 }
Youhan Wang4001d252016-05-11 10:29:41 -07006388 }
6389
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006390 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006391 * Return the Preferred Roaming List Version.
6392 *
6393 * @param subId the subscription ID that this request applies to.
6394 * @return PRLVersion or null if error.
6395 */
6396 @Override
6397 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006398 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006399 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400
6401 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006402 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 if (phone == null) {
6404 return null;
6405 }
6406 String cdmaPrlVersion = null;
6407 try {
6408 cdmaPrlVersion = phone.getCdmaPrlVersion();
6409 } catch (Exception e) {
6410 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6411 }
6412 return cdmaPrlVersion;
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006415 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006416 }
6417
6418 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006419 * Get snapshot of Telephony histograms
6420 * @return List of Telephony histograms
6421 * @hide
6422 */
6423 @Override
6424 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6426 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427
6428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 return RIL.getTelephonyRILTimingHistograms();
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006434 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006435
6436 /**
6437 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006438 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6439 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006440 * Require system privileges. In the future we may add this to carrier APIs.
6441 *
Michele Berionne482f8202018-11-27 18:57:59 -08006442 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006443 */
6444 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006445 @TelephonyManager.SetCarrierRestrictionResult
6446 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006447 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006448 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006449
Michele Berionne482f8202018-11-27 18:57:59 -08006450 if (carrierRestrictionRules == null) {
6451 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006452 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006453
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006454 final long identity = Binder.clearCallingIdentity();
6455 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006456 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006457 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006461 }
6462
6463 /**
6464 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006465 * Get the allowed carrier list and the excluded carrier list, including the priority between
6466 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006467 * Require system privileges. In the future we may add this to carrier APIs.
6468 *
Michele Berionne482f8202018-11-27 18:57:59 -08006469 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006470 */
6471 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006472 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006473 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006474 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006478 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6479 if (response instanceof CarrierRestrictionRules) {
6480 return (CarrierRestrictionRules) response;
6481 }
6482 // Response is an Exception of some kind,
6483 // which is signalled to the user as a NULL retval
6484 return null;
6485 } catch (Exception e) {
6486 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6487 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006491 }
6492
fionaxu59545b42016-05-25 15:53:37 -07006493 /**
6494 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6495 * @param subId the subscription ID that this action applies to.
6496 * @param enabled control enable or disable metered apns.
6497 * {@hide}
6498 */
6499 @Override
6500 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6501 enforceModifyPermission();
6502 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503
6504 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006505 if (phone == null) {
6506 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6507 return;
6508 }
6509 try {
6510 phone.carrierActionSetMeteredApnsEnabled(enabled);
6511 } catch (Exception e) {
6512 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 } finally {
6514 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006515 }
6516 }
6517
6518 /**
6519 * Action set from carrier signalling broadcast receivers to enable/disable radio
6520 * @param subId the subscription ID that this action applies to.
6521 * @param enabled control enable or disable radio.
6522 * {@hide}
6523 */
6524 @Override
6525 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6526 enforceModifyPermission();
6527 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528
6529 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006530 if (phone == null) {
6531 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6532 return;
6533 }
6534 try {
6535 phone.carrierActionSetRadioEnabled(enabled);
6536 } catch (Exception e) {
6537 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 } finally {
6539 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006540 }
6541 }
6542
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006543 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006544 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6545 * network status based on which carrier apps could apply actions accordingly,
6546 * enable/disable default url handler for example.
6547 *
6548 * @param subId the subscription ID that this action applies to.
6549 * @param report control start/stop reporting the default network status.
6550 * {@hide}
6551 */
6552 @Override
6553 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6554 enforceModifyPermission();
6555 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556
6557 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006558 if (phone == null) {
6559 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6560 return;
6561 }
6562 try {
6563 phone.carrierActionReportDefaultNetworkStatus(report);
6564 } catch (Exception e) {
6565 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 } finally {
6567 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006568 }
6569 }
6570
6571 /**
fionaxud9622282017-07-17 17:51:30 -07006572 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6573 * @param subId the subscription ID that this action applies to.
6574 * {@hide}
6575 */
6576 @Override
6577 public void carrierActionResetAll(int subId) {
6578 enforceModifyPermission();
6579 final Phone phone = getPhone(subId);
6580 if (phone == null) {
6581 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6582 return;
6583 }
6584 try {
6585 phone.carrierActionResetAll();
6586 } catch (Exception e) {
6587 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6588 }
6589 }
6590
6591 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006592 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6593 * bug report is being generated.
6594 */
6595 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006596 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006597 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6598 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006599 writer.println("Permission Denial: can't dump Phone from pid="
6600 + Binder.getCallingPid()
6601 + ", uid=" + Binder.getCallingUid()
6602 + "without permission "
6603 + android.Manifest.permission.DUMP);
6604 return;
6605 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006606 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006607 }
Jack Yueb89b242016-06-22 13:27:47 -07006608
Brad Ebingerdac2f002018-04-03 15:17:52 -07006609 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006610 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6611 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6612 @NonNull String[] args) {
6613 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6614 this, in.getFileDescriptor(), out.getFileDescriptor(),
6615 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006616 }
6617
Jack Yueb89b242016-06-22 13:27:47 -07006618 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006619 * Get aggregated video call data usage since boot.
6620 *
6621 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6622 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006623 * {@hide}
6624 */
6625 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006626 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006627 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6628 null);
6629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 // NetworkStatsService keeps tracking the active network interface and identity. It
6633 // records the delta with the corresponding network identity.
6634 // We just return the total video call data usage snapshot since boot.
6635 Phone phone = getPhone(subId);
6636 if (phone != null) {
6637 return phone.getVtDataUsage(perUidStats);
6638 }
6639 return null;
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006642 }
Jack Yueb89b242016-06-22 13:27:47 -07006643 }
Jack Yu75ab2952016-07-08 14:29:33 -07006644
6645 /**
6646 * Policy control of data connection. Usually used when data limit is passed.
6647 * @param enabled True if enabling the data, otherwise disabling.
6648 * @param subId Subscription index
6649 * {@hide}
6650 */
6651 @Override
6652 public void setPolicyDataEnabled(boolean enabled, int subId) {
6653 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 Phone phone = getPhone(subId);
6658 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006659 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 }
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006663 }
6664 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006665
6666 /**
6667 * Get Client request stats
6668 * @return List of Client Request Stats
6669 * @hide
6670 */
6671 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006672 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6673 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006675 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006676 return null;
6677 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006678 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 if (phone != null) {
6683 return phone.getClientRequestStats();
6684 }
6685
6686 return null;
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
6689 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006690 }
6691
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006692 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006693 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006694 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006695 }
Jack Yueb4124c2017-02-16 15:32:43 -08006696
6697 /**
Grace Chen70990072017-03-24 17:21:30 -07006698 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006699 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006700 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006701 * @param state State of SIM (power down, power up, pass through)
6702 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6703 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6704 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006705 *
6706 **/
6707 @Override
Grace Chen70990072017-03-24 17:21:30 -07006708 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006709 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006710 Phone phone = PhoneFactory.getPhone(slotIndex);
6711
vagdeviaf9a5b92018-08-15 16:01:53 -07006712 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006717 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 }
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006721 }
6722 }
Shuo Qiandd210312017-04-12 22:11:33 +00006723
Tyler Gunn65d45c22017-06-05 11:22:26 -07006724 private boolean isUssdApiAllowed(int subId) {
6725 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006726 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006727 if (configManager == null) {
6728 return false;
6729 }
6730 PersistableBundle pb = configManager.getConfigForSubId(subId);
6731 if (pb == null) {
6732 return false;
6733 }
6734 return pb.getBoolean(
6735 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6736 }
6737
Shuo Qiandd210312017-04-12 22:11:33 +00006738 /**
6739 * Check if phone is in emergency callback mode
6740 * @return true if phone is in emergency callback mode
6741 * @param subId sub id
6742 */
goneil9c5f4872017-12-05 14:07:56 -08006743 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006744 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006745 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
6750 if (phone != null) {
6751 return phone.isInEcm();
6752 } else {
6753 return false;
6754 }
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006757 }
6758 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006759
6760 /**
6761 * Get the current signal strength information for the given subscription.
6762 * Because this information is not updated when the device is in a low power state
6763 * it should not be relied-upon to be current.
6764 * @param subId Subscription index
6765 * @return the most recent cached signal strength info from the modem
6766 */
6767 @Override
6768 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 Phone p = getPhone(subId);
6772 if (p == null) {
6773 return null;
6774 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 return p.getSignalStrength();
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
6779 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006780 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006781
Pengquan Meng77b7f132018-08-22 14:49:57 -07006782 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006783 * Get the current modem radio state for the given slot.
6784 * @param slotIndex slot index.
6785 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006786 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006787 * @return the current radio power state from the modem
6788 */
6789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006791 Phone phone = PhoneFactory.getPhone(slotIndex);
6792 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6794 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006795 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6796 }
6797
6798 final long identity = Binder.clearCallingIdentity();
6799 try {
6800 return phone.getRadioPowerState();
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
6803 }
6804 }
6805 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6806 }
6807
6808 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006809 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6810 *
6811 * <p>Requires one of the following permissions:
6812 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6813 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6814 * privileges.
6815 *
6816 * @param subId subscription id
6817 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6818 * {@code false}.
6819 */
6820 @Override
6821 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006822 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6823 null /* message */);
6824
Pengquan Menga1bb6272018-09-06 09:59:22 -07006825 boolean isEnabled = false;
6826 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006827 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006828 Phone phone = getPhone(subId);
6829 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006830 } catch (Exception e) {
6831 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6832 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006833 } finally {
6834 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006835 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006836 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006837 }
6838
6839
6840 /**
6841 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6842 *
6843 * <p> Requires permission:
6844 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6845 * privileges.
6846 *
6847 * @param subId subscription id
6848 * @param isEnabled {@code true} means enable, {@code false} means disable.
6849 */
6850 @Override
6851 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6853 mApp, subId, "setDataRoamingEnabled");
6854
Pengquan Menga1bb6272018-09-06 09:59:22 -07006855 final long identity = Binder.clearCallingIdentity();
6856 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006857 Phone phone = getPhone(subId);
6858 if (phone != null) {
6859 phone.setDataRoamingEnabled(isEnabled);
6860 }
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006863 }
6864 }
6865
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006866 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006867 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006868 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6869 mApp, subId, "isManualNetworkSelectionAllowed");
6870
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006871 boolean isAllowed = true;
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006874 Phone phone = getPhone(subId);
6875 if (phone != null) {
6876 isAllowed = phone.isCspPlmnEnabled();
6877 }
6878 } finally {
6879 Binder.restoreCallingIdentity(identity);
6880 }
6881 return isAllowed;
6882 }
6883
6884 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006885 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006886 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006887 try {
6888 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006889 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006890 } catch (SecurityException e) {
6891 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6892 // has carrier privileges on an active UICC
6893 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6894 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006895 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006896 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006897 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006898
6899 final long identity = Binder.clearCallingIdentity();
6900 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006901 UiccController uiccController = UiccController.getInstance();
6902 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006903 if (hasReadPermission) {
6904 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006905 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006906
6907 // Remove private info if the caller doesn't have access
6908 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6909 for (UiccCardInfo cardInfo : cardInfos) {
6910 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6911 // is available
6912 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6913 if (card == null || card.getUiccProfile() == null) {
6914 // assume no access if the card or profile is unavailable
6915 filteredInfos.add(cardInfo.getUnprivileged());
6916 continue;
6917 }
6918 UiccProfile profile = card.getUiccProfile();
6919 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6920 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6921 filteredInfos.add(cardInfo);
6922 } else {
6923 filteredInfos.add(cardInfo.getUnprivileged());
6924 }
6925 }
6926 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006927 } finally {
6928 Binder.restoreCallingIdentity(identity);
6929 }
6930 }
6931
6932 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006933 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006934 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6939 if (slots == null) {
6940 Rlog.i(LOG_TAG, "slots is null.");
6941 return null;
6942 }
6943
6944 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6945 for (int i = 0; i < slots.length; i++) {
6946 UiccSlot slot = slots[i];
6947 if (slot == null) {
6948 continue;
6949 }
6950
Jordan Liu7be7e652019-05-06 18:55:02 +00006951 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 UiccCard card = slot.getUiccCard();
6953 if (card != null) {
6954 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006955 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006956 cardId = slot.getEid();
6957 if (TextUtils.isEmpty(cardId)) {
6958 cardId = slot.getIccId();
6959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 }
6961
Jordan Liu857451f2019-05-09 16:35:35 -07006962 if (cardId != null) {
6963 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6964 // if cardId is an EID, it's all digits so this is fine
6965 cardId = IccUtils.stripTrailingFs(cardId);
6966 }
6967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 int cardState = 0;
6969 switch (slot.getCardState()) {
6970 case CARDSTATE_ABSENT:
6971 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6972 break;
6973 case CARDSTATE_PRESENT:
6974 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6975 break;
6976 case CARDSTATE_ERROR:
6977 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6978 break;
6979 case CARDSTATE_RESTRICTED:
6980 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6981 break;
6982 default:
6983 break;
6984
6985 }
6986
6987 infos[i] = new UiccSlotInfo(
6988 slot.isActive(),
6989 slot.isEuicc(),
6990 cardId,
6991 cardState,
6992 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006993 slot.isExtendedApduSupported(),
6994 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 }
6996 return infos;
6997 } finally {
6998 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007000 }
7001
7002 @Override
7003 public boolean switchSlots(int[] physicalSlots) {
7004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005
7006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
7011 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007012 }
Jack Yu4c988042018-02-27 15:30:01 -08007013
7014 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007015 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007016 final long identity = Binder.clearCallingIdentity();
7017 try {
7018 return UiccController.getInstance().getCardIdForDefaultEuicc();
7019 } finally {
7020 Binder.restoreCallingIdentity(identity);
7021 }
7022 }
7023
7024 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007025 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7026 enforceModifyPermission();
7027 final Phone phone = getPhone(subId);
7028 if (phone == null) {
7029 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7030 return;
7031 }
7032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 phone.setRadioIndicationUpdateMode(filters, mode);
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
7038 }
Jack Yu4c988042018-02-27 15:30:01 -08007039 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007040
7041 /**
goneil47ffb6e2018-04-06 15:40:58 -07007042 * A test API to reload the UICC profile.
7043 *
7044 * <p>Requires that the calling app has permission
7045 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7046 * @hide
7047 */
7048 @Override
7049 public void refreshUiccProfile(int subId) {
7050 enforceModifyPermission();
7051
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 Phone phone = getPhone(subId);
7055 if (phone == null) {
7056 return;
7057 }
7058 UiccCard uiccCard = phone.getUiccCard();
7059 if (uiccCard == null) {
7060 return;
7061 }
7062 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7063 if (uiccProfile == null) {
7064 return;
7065 }
7066 uiccProfile.refresh();
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 }
7071
7072 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007073 * Returns false if the mobile data is disabled by default, otherwise return true.
7074 */
7075 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007076 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007077 }
7078
7079 /**
7080 * Returns true if the data roaming is enabled by default, i.e the system property
7081 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7082 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7083 */
7084 private boolean getDefaultDataRoamingEnabled(int subId) {
7085 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007086 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007087 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007088 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7089 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7090 return isDataRoamingEnabled;
7091 }
7092
7093 /**
7094 * Returns the default network type for the given {@code subId}, if the default network type is
7095 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7096 */
7097 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007098 List<Integer> list = TelephonyProperties.default_network();
7099 int phoneId = mSubscriptionController.getPhoneId(subId);
7100 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7101 return list.get(phoneId);
7102 }
7103 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007104 }
fionaxua13278b2018-03-21 00:08:13 -07007105
7106 @Override
7107 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007108 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007109 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110
7111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 final Phone phone = getPhone(subId);
7114 if (phone == null) {
7115 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7116 return;
7117 }
chen xueaba88a2019-03-15 13:15:10 -07007118 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7119 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 } finally {
7121 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007122 }
fionaxua13278b2018-03-21 00:08:13 -07007123 }
7124
7125 @Override
7126 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007127 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128
7129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 final Phone phone = getPhone(subId);
7132 if (phone == null) {
7133 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7134 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7135 }
7136 return phone.getCarrierIdListVersion();
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007139 }
fionaxua13278b2018-03-21 00:08:13 -07007140 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007141
7142 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007143 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7144 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007146 mApp, subId, callingPackage, callingFeatureId,
7147 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007148 return -1;
7149 }
7150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007158
7159 @Override
7160 public int getCdmaRoamingMode(int subId) {
7161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7162 mApp, subId, "getCdmaRoamingMode");
7163
7164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
7170 }
7171
7172 @Override
7173 public boolean setCdmaRoamingMode(int subId, int mode) {
7174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7175 mApp, subId, "setCdmaRoamingMode");
7176
7177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
7183 }
7184
7185 @Override
7186 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7188 mApp, subId, "setCdmaSubscriptionMode");
7189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7193 } finally {
7194 Binder.restoreCallingIdentity(identity);
7195 }
7196 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007197
sqianc5eccab2018-10-19 18:46:41 -07007198 @Override
sqian8c685422019-02-22 15:55:18 -08007199 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007200 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007202 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7203 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007204 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7205 }
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
sqian854d44b2018-12-12 16:48:18 -08007208 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7209 for (Phone phone: PhoneFactory.getPhones()) {
7210 if (phone.getEmergencyNumberTracker() != null
7211 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7212 emergencyNumberListInternal.put(
7213 phone.getSubId(),
7214 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7215 }
sqian11b7a0e2018-12-05 18:48:28 -08007216 }
sqian854d44b2018-12-12 16:48:18 -08007217 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
sqianc5eccab2018-10-19 18:46:41 -07007221 }
7222
7223 @Override
sqian8c685422019-02-22 15:55:18 -08007224 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007226 if (!exactMatch) {
7227 TelephonyPermissions
7228 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007229 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007230 }
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
sqian854d44b2018-12-12 16:48:18 -08007233 for (Phone phone: PhoneFactory.getPhones()) {
7234 if (phone.getEmergencyNumberTracker() != null
7235 && phone.getEmergencyNumberTracker() != null) {
7236 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7237 number, exactMatch)) {
7238 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007239 }
7240 }
sqian11b7a0e2018-12-05 18:48:28 -08007241 }
7242 return false;
7243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
7246 }
7247
sqianf4ca7ed2019-01-15 18:32:07 -08007248 /**
7249 * Update emergency number list for test mode.
7250 */
7251 @Override
7252 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7253 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7254 "updateEmergencyNumberListTestMode");
7255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 for (Phone phone: PhoneFactory.getPhones()) {
7259 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7260 if (tracker != null) {
7261 tracker.executeEmergencyNumberTestModeCommand(action, num);
7262 }
7263 }
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
7269 /**
7270 * Get the full emergency number list for test mode.
7271 */
7272 @Override
7273 public List<String> getEmergencyNumberListTestMode() {
7274 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7275 "getEmergencyNumberListTestMode");
7276
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 Set<String> emergencyNumbers = new HashSet<>();
7280 for (Phone phone: PhoneFactory.getPhones()) {
7281 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7282 if (tracker != null) {
7283 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7284 emergencyNumbers.add(num.getNumber());
7285 }
7286 }
7287 }
7288 return new ArrayList<>(emergencyNumbers);
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
7292 }
7293
chen xud6b45bd2018-10-30 22:27:10 -07007294 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007295 public int getEmergencyNumberDbVersion(int subId) {
7296 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7297
7298 final long identity = Binder.clearCallingIdentity();
7299 try {
7300 final Phone phone = getPhone(subId);
7301 if (phone == null) {
7302 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7303 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7304 }
7305 return phone.getEmergencyNumberDbVersion();
7306 } finally {
7307 Binder.restoreCallingIdentity(identity);
7308 }
7309 }
7310
7311 @Override
7312 public void notifyOtaEmergencyNumberDbInstalled() {
7313 enforceModifyPermission();
7314
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 for (Phone phone: PhoneFactory.getPhones()) {
7318 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7319 if (tracker != null) {
7320 tracker.updateOtaEmergencyNumberDatabase();
7321 }
7322 }
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
7327
7328 @Override
7329 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7330 enforceActiveEmergencySessionPermission();
7331
7332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 for (Phone phone: PhoneFactory.getPhones()) {
7335 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7336 if (tracker != null) {
7337 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7338 }
7339 }
7340 } finally {
7341 Binder.restoreCallingIdentity(identity);
7342 }
7343 }
7344
7345 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007346 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7347 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7348 Phone phone = getPhone(subId);
7349 if (phone == null) {
7350 return null;
7351 }
7352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 UiccProfile profile = UiccController.getInstance()
7355 .getUiccProfileForPhone(phone.getPhoneId());
7356 if (profile != null) {
7357 return profile.getCertsFromCarrierPrivilegeAccessRules();
7358 }
7359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
7362 return null;
7363 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007364
7365 /**
7366 * Enable or disable a modem stack.
7367 */
7368 @Override
7369 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7370 enforceModifyPermission();
7371
7372 final long identity = Binder.clearCallingIdentity();
7373 try {
7374 Phone phone = PhoneFactory.getPhone(slotIndex);
7375 if (phone == null) {
7376 return false;
7377 } else {
7378 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7379 }
7380 } finally {
7381 Binder.restoreCallingIdentity(identity);
7382 }
7383 }
Michelecea4cf22018-12-21 15:00:11 -08007384
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007385 /**
7386 * Whether a modem stack is enabled or not.
7387 */
7388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007389 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7390 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007391 Phone phone = PhoneFactory.getPhone(slotIndex);
7392 if (phone == null) return false;
7393
7394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007395 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7396 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007397 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7398 }
7399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007402 try {
7403 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7404 } catch (NoSuchElementException ex) {
7405 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7406 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
7410 }
7411
Michelecea4cf22018-12-21 15:00:11 -08007412 @Override
Michele0ea7d782019-03-19 14:58:42 -07007413 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007414 enforceModifyPermission();
7415
7416 final long identity = Binder.clearCallingIdentity();
7417 try {
7418 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007419 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007420 .commit();
7421 } finally {
7422 Binder.restoreCallingIdentity(identity);
7423 }
7424 }
7425
7426 @Override
Michele0ea7d782019-03-19 14:58:42 -07007427 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007428 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007430 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7431 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007432 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007433 }
Michelecea4cf22018-12-21 15:00:11 -08007434
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
Michele0ea7d782019-03-19 14:58:42 -07007437 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007442
Michele0ea7d782019-03-19 14:58:42 -07007443 @TelephonyManager.IsMultiSimSupportedResult
7444 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007445 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7446 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7447 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007448 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7449 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007450 }
7451 // Check if the hardware supports multisim functionality. If usage of multisim is not
7452 // supported by the modem, indicate that it is restricted.
7453 PhoneCapability staticCapability =
7454 mPhoneConfigurationManager.getStaticPhoneCapability();
7455 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007456 loge("isMultiSimSupportedInternal: no static configuration available");
7457 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007458 }
7459 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007460 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7461 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007462 }
7463 // Check if support of multiple SIMs is restricted by carrier
7464 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007465 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007466 }
7467
Michele0ea7d782019-03-19 14:58:42 -07007468 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007469 }
7470
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007471 /**
7472 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007473 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7474 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7475 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007476 * @param numOfSims number of active sims we want to switch to
7477 */
7478 @Override
7479 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007480 if (numOfSims == 1) {
7481 enforceModifyPermission();
7482 } else {
7483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7484 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7485 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007486 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007487
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007488 try {
Michele30b57b22019-03-01 12:01:14 -08007489 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007490 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007491 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7492 return;
7493 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007494 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
7498 }
7499
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007500 @Override
7501 public boolean isApplicationOnUicc(int subId, int appType) {
7502 enforceReadPrivilegedPermission("isApplicationOnUicc");
7503 Phone phone = getPhone(subId);
7504 if (phone == null) {
7505 return false;
7506 }
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 UiccCard uiccCard = phone.getUiccCard();
7510 if (uiccCard == null) {
7511 return false;
7512 }
7513 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7514 if (uiccProfile == null) {
7515 return false;
7516 }
7517 if (TelephonyManager.APPTYPE_SIM <= appType
7518 && appType <= TelephonyManager.APPTYPE_ISIM) {
7519 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7520 }
7521 return false;
7522 } finally {
7523 Binder.restoreCallingIdentity(identity);
7524 }
7525 }
7526
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007527 /**
chen xub4baa772019-04-03 10:23:41 -07007528 * Get whether making changes to modem configurations will trigger reboot.
7529 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007530 */
7531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007532 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7533 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007535 mApp, subId, callingPackage, callingFeatureId,
7536 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007537 return false;
7538 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
7541 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
7545 }
7546
Nathan Harold29f5f052019-02-15 13:41:57 -08007547 private void updateModemStateMetrics() {
7548 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7549 // TODO: check the state for each modem if the api is ready.
7550 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7551 }
7552
Pengquan Meng3889a572019-01-23 11:16:29 -08007553 @Override
7554 public int[] getSlotsMapping() {
7555 enforceReadPrivilegedPermission("getSlotsMapping");
7556
7557 final long identity = Binder.clearCallingIdentity();
7558 try {
7559 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7560 // All logical slots should have a mapping to a physical slot.
7561 int[] logicalSlotsMapping = new int[phoneCount];
7562 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7563 for (int i = 0; i < slotInfos.length; i++) {
7564 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7565 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7566 }
7567 }
7568 return logicalSlotsMapping;
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
7572 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007573
7574 /**
7575 * Get the IRadio HAL Version
7576 */
7577 @Override
7578 public int getRadioHalVersion() {
7579 Phone phone = getDefaultPhone();
7580 if (phone == null) return -1;
7581 HalVersion hv = phone.getHalVersion();
7582 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7583 return hv.major * 100 + hv.minor;
7584 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007585
7586 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007587 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7588 * corresponding network requests on a subId.
7589 *
7590 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007591 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007592 * 2) APN is un-metered for this subscription, or
7593 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7594 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7595 *
7596 * @return whether data is allowed for a apn type.
7597 *
7598 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007599 */
7600 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007601 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007602 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7603 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007604
7605 // Now that all security checks passes, perform the operation as ourselves.
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 Phone phone = getPhone(subId);
7609 if (phone == null) return false;
7610
Jack Yu41407ee2019-05-13 16:54:09 -07007611 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007612 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
7616 }
7617
7618 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007619 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007620 enforceReadPrivilegedPermission("isApnMetered");
7621
7622 // Now that all security checks passes, perform the operation as ourselves.
7623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 Phone phone = getPhone(subId);
7626 if (phone == null) return true; // By default return true.
7627
Jack Yu41407ee2019-05-13 16:54:09 -07007628 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
7632 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007633
7634 @Override
7635 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7636 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7637 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7638 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7639 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7640 }
7641 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7642 Intent intent = new Intent();
7643 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7644 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7645 // Bring up choose default SMS subscription dialog right now
7646 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7647 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7648 mApp.startActivity(intent);
7649 }
chen xud5ca2d52019-05-28 15:20:57 -07007650
7651 @Override
7652 public String getMmsUAProfUrl(int subId) {
7653 //TODO investigate if this API should require proper permission check in R b/133791609
7654 final long identity = Binder.clearCallingIdentity();
7655 try {
7656 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7657 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
7662
7663 @Override
7664 public String getMmsUserAgent(int subId) {
7665 //TODO investigate if this API should require proper permission check in R b/133791609
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7669 .getString(com.android.internal.R.string.config_mms_user_agent);
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
7672 }
7673 }
Jack Yub07d4972019-05-28 16:12:25 -07007674
7675 @Override
7676 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7677 enforceModifyPermission();
7678
7679 // Now that all security checks passes, perform the operation as ourselves.
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 Phone phone = getPhone(subId);
7683 if (phone == null) return false;
7684
7685 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
7689 }
7690
7691 @Override
7692 public boolean isDataAllowedInVoiceCall(int subId) {
7693 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7694
7695 // Now that all security checks passes, perform the operation as ourselves.
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 Phone phone = getPhone(subId);
7699 if (phone == null) return false;
7700
7701 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
7705 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007706
7707 /**
7708 * Updates whether conference event pacakge handling is enabled.
7709 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7710 * otherwise.
7711 */
7712 @Override
7713 public void setCepEnabled(boolean isCepEnabled) {
7714 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7715
7716 final long identity = Binder.clearCallingIdentity();
7717 try {
7718 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7719 for (Phone phone : PhoneFactory.getPhones()) {
7720 Phone defaultPhone = phone.getImsPhone();
7721 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7722 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7723 ImsPhoneCallTracker imsPhoneCallTracker =
7724 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7725 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7726 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7727 + imsPhone.getMsisdn());
7728 }
7729 }
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
7732 }
7733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007734}