blob: c8ff2611f888d170b150f8034cc8eacec654e979 [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;
changbetty7157e9e2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700177import java.io.FileDescriptor;
178import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800181import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800183import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100184import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700186import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189/**
190 * Implementation of the ITelephony interface.
191 */
Santos Cordon117fee72014-05-16 17:56:12 -0700192public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private static final String LOG_TAG = "PhoneInterfaceManager";
194 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
195 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198 // Message codes used with mMainThreadHandler
199 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700200 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
201 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202 private static final int CMD_OPEN_CHANNEL = 9;
203 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
204 private static final int CMD_CLOSE_CHANNEL = 11;
205 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800206 private static final int CMD_NV_READ_ITEM = 13;
207 private static final int EVENT_NV_READ_ITEM_DONE = 14;
208 private static final int CMD_NV_WRITE_ITEM = 15;
209 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
210 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
211 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700212 private static final int CMD_RESET_MODEM_CONFIG = 19;
213 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800214 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
215 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
216 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
217 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800218 private static final int CMD_SEND_ENVELOPE = 25;
219 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000220 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
221 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700222 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
223 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
224 private static final int CMD_EXCHANGE_SIM_IO = 31;
225 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
227 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700228 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700230 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
231 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700232 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
233 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
234 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700236 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
237 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
238 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
239 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700240 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
242 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243 private static final int CMD_SWITCH_SLOTS = 50;
244 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700245 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
246 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
247 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
248 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
249 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
250 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
251 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
252 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700253 private static final int CMD_GET_ALL_CELL_INFO = 60;
254 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
255 private static final int CMD_GET_CELL_LOCATION = 62;
256 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700257 private static final int CMD_MODEM_REBOOT = 64;
258 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700259 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
260 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800261 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
262 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263 private static final int CMD_GET_MODEM_STATUS = 70;
264 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700265 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
266 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700267 private static final int CMD_ERASE_MODEM_CONFIG = 74;
268 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800270 // Parameters of select command.
271 private static final int SELECT_COMMAND = 0xA4;
272 private static final int SELECT_P1 = 0x04;
273 private static final int SELECT_P2 = 0;
274 private static final int SELECT_P3 = 0x10;
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800281 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700282 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private AppOpsManager mAppOps;
284 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800285 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800286 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700287 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
Derek Tan97ebb422014-09-05 16:55:38 -0700289 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
290 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800291 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800292 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700293
Michelecea4cf22018-12-21 15:00:11 -0800294 // String to store multi SIM allowed
295 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
296
Derek Tan740e1672017-06-27 14:56:27 -0700297 // The AID of ISD-R.
298 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
299
yinxub1bed742017-04-17 11:45:04 -0700300 private NetworkScanRequestTracker mNetworkScanRequestTracker;
301
David Kelly5e06a7f2018-03-12 14:10:59 +0000302 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
303 private static final int MANUFACTURER_CODE_LENGTH = 8;
304
Derek Tan89e89d42014-07-08 17:00:10 -0700305 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 * Experiment flag to enable erase modem config on reset network, default value is false
307 */
308 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
309 "reset_network_erase_modem_config_enabled";
310
311 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700312 * A request object to use for transmitting data to an ICC.
313 */
314 private static final class IccAPDUArgument {
315 public int channel, cla, command, p1, p2, p3;
316 public String data;
317
318 public IccAPDUArgument(int channel, int cla, int command,
319 int p1, int p2, int p3, String data) {
320 this.channel = channel;
321 this.cla = cla;
322 this.command = command;
323 this.p1 = p1;
324 this.p2 = p2;
325 this.p3 = p3;
326 this.data = data;
327 }
328 }
329
330 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700331 * A request object to use for transmitting data to an ICC.
332 */
333 private static final class ManualNetworkSelectionArgument {
334 public OperatorInfo operatorInfo;
335 public boolean persistSelection;
336
337 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
338 this.operatorInfo = operatorInfo;
339 this.persistSelection = persistSelection;
340 }
341 }
342
343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
345 * request after sending. The main thread will notify the request when it is complete.
346 */
347 private static final class MainThreadRequest {
348 /** The argument to use for the request */
349 public Object argument;
350 /** The result of the request that is run on the main thread */
351 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 // The subscriber id that this request applies to. Defaults to
353 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
354 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Nathan Harold92bed182018-10-12 18:16:49 -0700356 // In cases where subId is unavailable, the caller needs to specify the phone.
357 public Phone phone;
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 public WorkSource workSource;
360
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 public MainThreadRequest(Object argument) {
362 this.argument = argument;
363 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364
Nathan Harold92bed182018-10-12 18:16:49 -0700365 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
366 this.argument = argument;
367 if (phone != null) {
368 this.phone = phone;
369 }
370 this.workSource = workSource;
371 }
372
vagdeviaf9a5b92018-08-15 16:01:53 -0700373 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800374 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800375 if (subId != null) {
376 this.subId = subId;
377 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700378 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800382 private static final class IncomingThirdPartyCallArgs {
383 public final ComponentName component;
384 public final String callId;
385 public final String callerDisplayName;
386
387 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
388 String callerDisplayName) {
389 this.component = component;
390 this.callId = callId;
391 this.callerDisplayName = callerDisplayName;
392 }
393 }
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 /**
396 * A handler that processes messages on the main thread in the phone process. Since many
397 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
398 * inbound binder threads to the main thread in the phone process. The Binder thread
399 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
400 * on, which will be notified when the operation completes and will contain the result of the
401 * request.
402 *
403 * <p>If a MainThreadRequest object is provided in the msg.obj field,
404 * note that request.result must be set to something non-null for the calling thread to
405 * unblock.
406 */
407 private final class MainThreadHandler extends Handler {
408 @Override
409 public void handleMessage(Message msg) {
410 MainThreadRequest request;
411 Message onCompleted;
412 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800415 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
417 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 case CMD_HANDLE_USSD_REQUEST: {
419 request = (MainThreadRequest) msg.obj;
420 final Phone phone = getPhoneFromRequest(request);
421 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
422 String ussdRequest = ussdObject.first;
423 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 if (!isUssdApiAllowed(request.subId)) {
426 // Carrier does not support use of this API, return failure.
427 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
428 UssdResponse response = new UssdResponse(ussdRequest, null);
429 Bundle returnData = new Bundle();
430 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
431 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700432
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 request.result = true;
434 notifyRequester(request);
435 return;
436 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700437
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 try {
439 request.result = phone != null
440 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
441 } catch (CallStateException cse) {
442 request.result = false;
443 }
444 // Wake up the requesting thread
445 notifyRequester(request);
446 break;
pkanwar32d516d2016-10-14 19:37:38 -0700447 }
448
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 final Phone phone = getPhoneFromRequest(request);
452 request.result = phone != null ?
453 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
454 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800463 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 if (uiccCard == null) {
465 loge("iccTransmitApduLogicalChannel: No UICC");
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
470 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 iccArgument.channel, iccArgument.cla, iccArgument.command,
473 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700475 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 break;
477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 ar = (AsyncResult) msg.obj;
480 request = (MainThreadRequest) ar.userObj;
481 if (ar.exception == null && ar.result != null) {
482 request.result = ar.result;
483 } else {
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
485 if (ar.result == null) {
486 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800487 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800489 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 } else {
491 loge("iccTransmitApduLogicalChannel: Unknown exception");
492 }
493 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 break;
496
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
498 request = (MainThreadRequest) msg.obj;
499 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 if (uiccCard == null) {
502 loge("iccTransmitApduBasicChannel: No UICC");
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 } else {
506 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
507 request);
508 uiccCard.iccTransmitApduBasicChannel(
509 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
510 iccArgument.p3, iccArgument.data, onCompleted);
511 }
512 break;
513
514 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("iccTransmitApduBasicChannel: Empty response");
523 } else if (ar.exception instanceof CommandException) {
524 loge("iccTransmitApduBasicChannel: CommandException: " +
525 ar.exception);
526 } else {
527 loge("iccTransmitApduBasicChannel: Unknown exception");
528 }
529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 break;
532
533 case CMD_EXCHANGE_SIM_IO:
534 request = (MainThreadRequest) msg.obj;
535 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 if (uiccCard == null) {
538 loge("iccExchangeSimIO: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
543 request);
544 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
545 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
546 iccArgument.data, onCompleted);
547 }
548 break;
549
550 case EVENT_EXCHANGE_SIM_IO_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6f, 0, (byte[])null);
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 break;
560
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 case CMD_SEND_ENVELOPE:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 if (uiccCard == null) {
565 loge("sendEnvelopeWithStatus: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
570 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
571 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 break;
573
574 case EVENT_SEND_ENVELOPE_DONE:
575 ar = (AsyncResult) msg.obj;
576 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700577 if (ar.exception == null && ar.result != null) {
578 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
581 if (ar.result == null) {
582 loge("sendEnvelopeWithStatus: Empty response");
583 } else if (ar.exception instanceof CommandException) {
584 loge("sendEnvelopeWithStatus: CommandException: " +
585 ar.exception);
586 } else {
587 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
588 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 break;
592
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 case CMD_OPEN_CHANNEL:
594 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800595 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800599 request.result = new IccOpenLogicalChannelResponse(-1,
600 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800604 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
605 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
609 case EVENT_OPEN_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 int[] result = (int[]) ar.result;
615 int channelId = result[0];
616 byte[] selectResponse = null;
617 if (result.length > 1) {
618 selectResponse = new byte[result.length - 1];
619 for (int i = 1; i < result.length; ++i) {
620 selectResponse[i - 1] = (byte) result[i];
621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 if (ar.result == null) {
627 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 if (ar.exception != null) {
630 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
631 }
632
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700634 if (ar.exception instanceof CommandException) {
635 CommandException.Error error =
636 ((CommandException) (ar.exception)).getCommandError();
637 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700639 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 }
642 }
643 openChannelResp = new IccOpenLogicalChannelResponse(
644 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700646 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case CMD_CLOSE_CHANNEL:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900655 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
659 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800664 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
665 break;
666
667 case CMD_NV_READ_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800670 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
671 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
674 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 request.result = "";
681 if (ar.result == null) {
682 loge("nvReadItem: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("nvReadItem: CommandException: " +
685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800687 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Jake Hambye994d462014-02-03 13:10:13 -0800693 case CMD_NV_WRITE_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
696 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_WRITE_ITEM_DONE:
702 handleNullReturnEvent(msg, "nvWriteItem");
703 break;
704
705 case CMD_NV_WRITE_CDMA_PRL:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800708 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
711 case EVENT_NV_WRITE_CDMA_PRL_DONE:
712 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
713 break;
714
chen xu6dac5ab2018-10-26 17:39:23 -0700715 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800716 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700717 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
chen xu6dac5ab2018-10-26 17:39:23 -0700721 case EVENT_RESET_MODEM_CONFIG_DONE:
722 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800723 break;
724
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 case CMD_GET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700728 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 break;
730
731 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
732 ar = (AsyncResult) msg.obj;
733 request = (MainThreadRequest) ar.userObj;
734 if (ar.exception == null && ar.result != null) {
735 request.result = ar.result; // Integer
736 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800737 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 if (ar.result == null) {
739 loge("getPreferredNetworkType: Empty response");
740 } else if (ar.exception instanceof CommandException) {
741 loge("getPreferredNetworkType: CommandException: " +
742 ar.exception);
743 } else {
744 loge("getPreferredNetworkType: Unknown exception");
745 }
746 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case CMD_SET_PREFERRED_NETWORK_TYPE:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
753 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
758 handleNullReturnEvent(msg, "setPreferredNetworkType");
759 break;
760
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
762 request = (MainThreadRequest)msg.obj;
763 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
767 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
768 ar = (AsyncResult)msg.obj;
769 request = (MainThreadRequest)ar.userObj;
770 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000772 break;
773
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 case CMD_SET_VOICEMAIL_NUMBER:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
777 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800778 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
779 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800780 break;
781
782 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
783 handleNullReturnEvent(msg, "setVoicemailNumber");
784 break;
785
Stuart Scott54788802015-03-30 13:18:01 -0700786 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
789 request);
790 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
795 break;
796
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 case CMD_PERFORM_NETWORK_SCAN:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
800 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
801 break;
802
803 case EVENT_PERFORM_NETWORK_SCAN_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 CellNetworkScanResult cellScanResult;
807 if (ar.exception == null && ar.result != null) {
808 cellScanResult = new CellNetworkScanResult(
809 CellNetworkScanResult.STATUS_SUCCESS,
810 (List<OperatorInfo>) ar.result);
811 } else {
812 if (ar.result == null) {
813 loge("getCellNetworkScanResults: Empty response");
814 }
815 if (ar.exception != null) {
816 loge("getCellNetworkScanResults: Exception: " + ar.exception);
817 }
818 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
822 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
824 } else if (error == CommandException.Error.GENERIC_FAILURE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
826 }
827 }
828 cellScanResult = new CellNetworkScanResult(errorCode, null);
829 }
830 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700831 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
834 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
835 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700836 ManualNetworkSelectionArgument selArg =
837 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700838 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
839 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700840 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
841 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
844 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null) {
848 request.result = true;
849 } else {
850 request.result = false;
851 loge("setNetworkSelectionModeManual " + ar.exception);
852 }
853 notifyRequester(request);
854 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700855 break;
856
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700857 case CMD_GET_MODEM_ACTIVITY_INFO:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700860 if (defaultPhone != null) {
861 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
862 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700863 break;
864
865 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 if (ar.result == null) {
872 loge("queryModemActivityInfo: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("queryModemActivityInfo: CommandException: " +
875 ar.exception);
876 } else {
877 loge("queryModemActivityInfo: Unknown exception");
878 }
879 }
Amit Mahajand4766222016-01-28 15:28:28 -0800880 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
881 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800882 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800883 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700885 break;
886
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 case CMD_SET_ALLOWED_CARRIERS:
888 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800889 CarrierRestrictionRules argument =
890 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800892 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
895 case EVENT_SET_ALLOWED_CARRIERS_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800901 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
902 if (ar.exception instanceof CommandException) {
903 loge("setAllowedCarriers: CommandException: " + ar.exception);
904 CommandException.Error error =
905 ((CommandException) (ar.exception)).getCommandError();
906 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
907 request.result =
908 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
909 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 } else {
911 loge("setAllowedCarriers: Unknown exception");
912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 break;
916
917 case CMD_GET_ALLOWED_CARRIERS:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700921 break;
922
923 case EVENT_GET_ALLOWED_CARRIERS_DONE:
924 ar = (AsyncResult) msg.obj;
925 request = (MainThreadRequest) ar.userObj;
926 if (ar.exception == null && ar.result != null) {
927 request.result = ar.result;
928 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800929 request.result = new IllegalStateException(
930 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700931 if (ar.result == null) {
932 loge("getAllowedCarriers: Empty response");
933 } else if (ar.exception instanceof CommandException) {
934 loge("getAllowedCarriers: CommandException: " +
935 ar.exception);
936 } else {
937 loge("getAllowedCarriers: Unknown exception");
938 }
939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700941 break;
942
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 request.result = new IllegalArgumentException(
950 "Failed to retrieve Forbidden Plmns");
951 if (ar.result == null) {
952 loge("getForbiddenPlmns: Empty response");
953 } else {
954 loge("getForbiddenPlmns: Unknown exception");
955 }
956 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800958 break;
959
960 case CMD_GET_FORBIDDEN_PLMNS:
961 request = (MainThreadRequest) msg.obj;
962 uiccCard = getUiccCardFromRequest(request);
963 if (uiccCard == null) {
964 loge("getForbiddenPlmns() UiccCard is null");
965 request.result = new IllegalArgumentException(
966 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969 }
970 Integer appType = (Integer) request.argument;
971 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
972 if (uiccApp == null) {
973 loge("getForbiddenPlmns() no app with specified type -- "
974 + appType);
975 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700976 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800977 break;
978 } else {
979 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
980 + " specified type -- " + appType);
981 }
982 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
983 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
984 onCompleted);
985 break;
986
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000987 case CMD_SWITCH_SLOTS:
988 request = (MainThreadRequest) msg.obj;
989 int[] physicalSlots = (int[]) request.argument;
990 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
991 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
992 break;
993
994 case EVENT_SWITCH_SLOTS_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700998 notifyRequester(request);
999 break;
1000 case CMD_GET_NETWORK_SELECTION_MODE:
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1003 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1004 break;
1005
1006 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception != null) {
1010 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1011 } else {
1012 int mode = ((int[]) ar.result)[0];
1013 if (mode == 0) {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1015 } else {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1017 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001018 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001019 notifyRequester(request);
1020 break;
1021 case CMD_GET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1024 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1025 break;
1026 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception != null) {
1030 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1031 } else {
1032 request.result = ((int[]) ar.result)[0];
1033 }
1034 notifyRequester(request);
1035 break;
1036 case CMD_SET_CDMA_ROAMING_MODE:
1037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1039 int mode = (int) request.argument;
1040 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1041 break;
1042 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 request.result = ar.exception == null;
1046 notifyRequester(request);
1047 break;
1048 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1051 int subscriptionMode = (int) request.argument;
1052 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1053 break;
1054 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 request.result = ar.exception == null;
1058 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001059 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 case CMD_GET_ALL_CELL_INFO:
1061 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001063 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 case EVENT_GET_ALL_CELL_INFO_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001068 // If a timeout occurs, the response will be null
1069 request.result = (ar.exception == null && ar.result != null)
1070 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 synchronized (request) {
1072 request.notifyAll();
1073 }
1074 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 case CMD_REQUEST_CELL_INFO_UPDATE:
1076 request = (MainThreadRequest) msg.obj;
1077 request.phone.requestCellInfoUpdate(request.workSource,
1078 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1079 break;
1080 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1084 try {
1085 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001087 cb.onError(
1088 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1089 ar.exception.getClass().getName(),
1090 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001093 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 } else {
1095 // use the result as returned
1096 cb.onCellInfo((List<CellInfo>) ar.result);
1097 }
1098 } catch (RemoteException re) {
1099 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1100 }
1101 break;
1102 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001103 request = (MainThreadRequest) msg.obj;
1104 WorkSource ws = (WorkSource) request.argument;
1105 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001106 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001108 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = ar.result;
1113 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001114 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001116 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 }
1118
1119 synchronized (request) {
1120 request.notifyAll();
1121 }
1122 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001123 case CMD_MODEM_REBOOT:
1124 request = (MainThreadRequest) msg.obj;
1125 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001126 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001127 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001128 case EVENT_CMD_MODEM_REBOOT_DONE:
1129 handleNullReturnEvent(msg, "rebootModem");
1130 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001131 case CMD_REQUEST_ENABLE_MODEM:
1132 request = (MainThreadRequest) msg.obj;
1133 boolean enable = (boolean) request.argument;
1134 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001136 PhoneConfigurationManager.getInstance()
1137 .enablePhone(request.phone, enable, onCompleted);
1138 break;
1139 case EVENT_ENABLE_MODEM_DONE:
1140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
1142 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001144 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 if ((boolean) request.result) {
1146 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1147 updateModemStateMetrics();
1148 } else {
1149 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1150 + ar.exception);
1151 }
1152 notifyRequester(request);
1153 break;
1154 case CMD_GET_MODEM_STATUS:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1157 PhoneConfigurationManager.getInstance()
1158 .getPhoneStatusFromModem(request.phone, onCompleted);
1159 break;
1160 case EVENT_GET_MODEM_STATUS_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 int id = request.phone.getPhoneId();
1164 if (ar.exception == null && ar.result != null) {
1165 request.result = ar.result;
1166 //update the cache as modem status has changed
1167 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1168 (boolean) request.result);
1169 } else {
1170 // Return true if modem status cannot be retrieved. For most cases,
1171 // modem status is on. And for older version modems, GET_MODEM_STATUS
1172 // and disable modem are not supported. Modem is always on.
1173 // TODO: this should be fixed in R to support a third
1174 // status UNKNOWN b/131631629
1175 request.result = true;
1176 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1177 + ar.exception);
1178 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001179 notifyRequester(request);
1180 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001181 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null && ar.result != null) {
1185 request.result = ar.result;
1186 } else {
1187 request.result = -1;
1188 loge("Failed to set Forbidden Plmns");
1189 if (ar.result == null) {
1190 loge("setForbidenPlmns: Empty response");
1191 } else if (ar.exception != null) {
1192 loge("setForbiddenPlmns: Exception: " + ar.exception);
1193 request.result = -1;
1194 } else {
1195 loge("setForbiddenPlmns: Unknown exception");
1196 }
1197 }
1198 notifyRequester(request);
1199 break;
1200 case CMD_SET_FORBIDDEN_PLMNS:
1201 request = (MainThreadRequest) msg.obj;
1202 uiccCard = getUiccCardFromRequest(request);
1203 if (uiccCard == null) {
1204 loge("setForbiddenPlmns: UiccCard is null");
1205 request.result = -1;
1206 notifyRequester(request);
1207 break;
1208 }
1209 Pair<Integer, List<String>> setFplmnsArgs =
1210 (Pair<Integer, List<String>>) request.argument;
1211 appType = setFplmnsArgs.first;
1212 List<String> fplmns = setFplmnsArgs.second;
1213 uiccApp = uiccCard.getApplicationByType(appType);
1214 if (uiccApp == null) {
1215 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1216 request.result = -1;
1217 loge("Failed to get UICC App");
1218 notifyRequester(request);
1219 } else {
1220 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1221 ((SIMRecords) uiccApp.getIccRecords())
1222 .setForbiddenPlmns(onCompleted, fplmns);
1223 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001224 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001225 case CMD_ERASE_MODEM_CONFIG:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1228 defaultPhone.eraseModemConfig(onCompleted);
1229 break;
1230 case EVENT_ERASE_MODEM_CONFIG_DONE:
1231 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001232 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 default:
1234 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1235 break;
1236 }
1237 }
Jake Hambye994d462014-02-03 13:10:13 -08001238
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 private void notifyRequester(MainThreadRequest request) {
1240 synchronized (request) {
1241 request.notifyAll();
1242 }
1243 }
1244
Jake Hambye994d462014-02-03 13:10:13 -08001245 private void handleNullReturnEvent(Message msg, String command) {
1246 AsyncResult ar = (AsyncResult) msg.obj;
1247 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1248 if (ar.exception == null) {
1249 request.result = true;
1250 } else {
1251 request.result = false;
1252 if (ar.exception instanceof CommandException) {
1253 loge(command + ": CommandException: " + ar.exception);
1254 } else {
1255 loge(command + ": Unknown exception");
1256 }
1257 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001258 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 }
1261
1262 /**
1263 * Posts the specified command to be executed on the main thread,
1264 * waits for the request to complete, and returns the result.
1265 * @see #sendRequestAsync
1266 */
1267 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001268 return sendRequest(
1269 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
1277 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1278 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001279 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
1282 /**
1283 * Posts the specified command to be executed on the main thread,
1284 * waits for the request to complete, and returns the result.
1285 * @see #sendRequestAsync
1286 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001287 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001288 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
Nathan Harold92bed182018-10-12 18:16:49 -07001296 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1297 return sendRequest(command, argument, subId, null, workSource);
1298 }
1299
1300 /**
1301 * Posts the specified command to be executed on the main thread,
1302 * waits for the request to complete, and returns the result.
1303 * @see #sendRequestAsync
1304 */
1305 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1306 return sendRequest(
1307 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1308 }
1309
1310 /**
1311 * Posts the specified command to be executed on the main thread,
1312 * waits for the request to complete, and returns the result.
1313 * @see #sendRequestAsync
1314 */
1315 private Object sendRequest(
1316 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1318 throw new RuntimeException("This method will deadlock if called from the main thread.");
1319 }
1320
Nathan Harold92bed182018-10-12 18:16:49 -07001321 MainThreadRequest request = null;
1322 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1323 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1324 } else if (phone != null) {
1325 request = new MainThreadRequest(argument, phone, workSource);
1326 } else {
1327 request = new MainThreadRequest(argument, subId, workSource);
1328 }
1329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 Message msg = mMainThreadHandler.obtainMessage(command, request);
1331 msg.sendToTarget();
1332
1333 // Wait for the request to complete
1334 synchronized (request) {
1335 while (request.result == null) {
1336 try {
1337 request.wait();
1338 } catch (InterruptedException e) {
1339 // Do nothing, go back and wait until the request is complete
1340 }
1341 }
1342 }
1343 return request.result;
1344 }
1345
1346 /**
1347 * Asynchronous ("fire and forget") version of sendRequest():
1348 * Posts the specified command to be executed on the main thread, and
1349 * returns immediately.
1350 * @see #sendRequest
1351 */
1352 private void sendRequestAsync(int command) {
1353 mMainThreadHandler.sendEmptyMessage(command);
1354 }
1355
1356 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001358 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 */
1360 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001361 sendRequestAsync(command, argument, null, null);
1362 }
1363
1364 /**
1365 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1366 * @see {@link #sendRequest(int,Object)}
1367 */
1368 private void sendRequestAsync(
1369 int command, Object argument, Phone phone, WorkSource workSource) {
1370 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001371 Message msg = mMainThreadHandler.obtainMessage(command, request);
1372 msg.sendToTarget();
1373 }
1374
1375 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 * Initialize the singleton PhoneInterfaceManager instance.
1377 * This is only done once, at startup, from PhoneApp.onCreate().
1378 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 synchronized (PhoneInterfaceManager.class) {
1381 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 } else {
1384 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1385 }
1386 return sInstance;
1387 }
1388 }
1389
1390 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001394 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
1415 ServiceManager.addService("phone", this);
1416 }
1417
Stuart Scott584921c2015-01-15 17:10:34 -08001418 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001419 if (request.phone != null) {
1420 return request.phone;
1421 } else {
1422 return getPhoneFromSubId(request.subId);
1423 }
1424 }
1425
1426 private Phone getPhoneFromSubId(int subId) {
1427 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1428 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001429 }
1430
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001431 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1432 Phone phone = getPhoneFromRequest(request);
1433 return phone == null ? null :
1434 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1435 }
1436
Wink Saville36469e72014-06-11 15:17:00 -07001437 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001439 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Naina Nallurid63128d2019-09-17 14:10:30 -07001442 private void sendEraseModemConfig(Phone phone) {
1443 if (phone != null) {
1444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1445 mApp, phone.getSubId(), "eraseModemConfig");
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1449 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
1452 }
1453 }
1454 }
1455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 if (DBG) log("dial: " + number);
1462 // No permission check needed here: This is just a wrapper around the
1463 // ACTION_DIAL intent, which is available to any app since it puts up
1464 // the UI before it does anything.
1465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001466 final long identity = Binder.clearCallingIdentity();
1467 try {
1468 String url = createTelUrl(number);
1469 if (url == null) {
1470 return;
1471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473 // PENDING: should we just silently fail if phone is offhook or ringing?
1474 PhoneConstants.State state = mCM.getState(subId);
1475 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1476 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1477 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1478 mApp.startActivity(intent);
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 }
1484
1485 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 if (DBG) log("call: " + number);
1491
1492 // This is just a wrapper around the ACTION_CALL intent, but we still
1493 // need to do a permission check since we're calling startActivity()
1494 // from the context of the phone app.
1495 enforceCallPermission();
1496
Jordan Liu1617b712019-07-10 15:06:26 -07001497 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 != AppOpsManager.MODE_ALLOWED) {
1499 return;
1500 }
1501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502 final long identity = Binder.clearCallingIdentity();
1503 try {
1504 String url = createTelUrl(number);
1505 if (url == null) {
1506 return;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001509 boolean isValid = false;
1510 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1511 if (slist != null) {
1512 for (SubscriptionInfo subInfoRecord : slist) {
1513 if (subInfoRecord.getSubscriptionId() == subId) {
1514 isValid = true;
1515 break;
1516 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001517 }
Wink Saville08874612014-08-31 19:19:58 -07001518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 if (!isValid) {
1520 return;
1521 }
Wink Saville08874612014-08-31 19:19:58 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1524 intent.putExtra(SUBSCRIPTION_KEY, subId);
1525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1526 mApp.startActivity(intent);
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
1529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001534 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1535 }
1536
Wink Savilleb564aae2014-10-23 10:18:09 -07001537 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001539 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001544
1545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1548 checkSimPin.start();
1549 return checkSimPin.unlockSim(null, pin);
1550 } finally {
1551 Binder.restoreCallingIdentity(identity);
1552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557
1558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1561 checkSimPuk.start();
1562 return checkSimPuk.unlockSim(puk, pin);
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
1568 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001569 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 * a synchronous one.
1571 */
1572 private static class UnlockSim extends Thread {
1573
1574 private final IccCard mSimCard;
1575
1576 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001577 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1578 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579
1580 // For replies from SimCard interface
1581 private Handler mHandler;
1582
1583 // For async handler to identify request type
1584 private static final int SUPPLY_PIN_COMPLETE = 100;
1585
1586 public UnlockSim(IccCard simCard) {
1587 mSimCard = simCard;
1588 }
1589
1590 @Override
1591 public void run() {
1592 Looper.prepare();
1593 synchronized (UnlockSim.this) {
1594 mHandler = new Handler() {
1595 @Override
1596 public void handleMessage(Message msg) {
1597 AsyncResult ar = (AsyncResult) msg.obj;
1598 switch (msg.what) {
1599 case SUPPLY_PIN_COMPLETE:
1600 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1601 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001602 mRetryCount = msg.arg1;
1603 if (ar.exception != null) {
1604 if (ar.exception instanceof CommandException &&
1605 ((CommandException)(ar.exception)).getCommandError()
1606 == CommandException.Error.PASSWORD_INCORRECT) {
1607 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1608 } else {
1609 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1610 }
1611 } else {
1612 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 mDone = true;
1615 UnlockSim.this.notifyAll();
1616 }
1617 break;
1618 }
1619 }
1620 };
1621 UnlockSim.this.notifyAll();
1622 }
1623 Looper.loop();
1624 }
1625
1626 /*
1627 * Use PIN or PUK to unlock SIM card
1628 *
1629 * If PUK is null, unlock SIM card with PIN
1630 *
1631 * If PUK is not null, unlock SIM card with PUK and set PIN code
1632 */
Wink Saville9de0f752013-10-22 19:04:03 -07001633 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634
1635 while (mHandler == null) {
1636 try {
1637 wait();
1638 } catch (InterruptedException e) {
1639 Thread.currentThread().interrupt();
1640 }
1641 }
1642 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1643
1644 if (puk == null) {
1645 mSimCard.supplyPin(pin, callback);
1646 } else {
1647 mSimCard.supplyPuk(puk, pin, callback);
1648 }
1649
1650 while (!mDone) {
1651 try {
1652 Log.d(LOG_TAG, "wait for done");
1653 wait();
1654 } catch (InterruptedException e) {
1655 // Restore the interrupted status
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001660 int[] resultArray = new int[2];
1661 resultArray[0] = mResult;
1662 resultArray[1] = mRetryCount;
1663 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 }
1665 }
1666
1667 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001668 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001669
1670 }
1671
Wink Savilleb564aae2014-10-23 10:18:09 -07001672 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 // No permission check needed here: this call is harmless, and it's
1674 // needed for the ServiceState.requestStateUpdate() call (which is
1675 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final Phone phone = getPhone(subId);
1679 if (phone != null) {
1680 phone.updateServiceLocation();
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001687 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001688 @Override
1689 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001690 return isRadioOnWithFeature(callingPackage, null);
1691 }
1692
1693
1694 @Override
1695 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1696 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1697 callingFeatureId);
1698 }
1699
1700 @Deprecated
1701 @Override
1702 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1703 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001704 }
1705
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001706 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001707 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001710 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 return false;
1712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 return isRadioOnForSubscriber(subId);
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 }
1721
1722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
1727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Wink Saville36469e72014-06-11 15:17:00 -07001739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
1754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone == null) {
1765 return false;
1766 }
1767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1768 toggleRadioOnOffForSubscriber(subId);
1769 }
1770 return true;
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
Wink Saville36469e72014-06-11 15:17:00 -07001775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001777 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 /*
1779 * If any of the Radios are available, it will need to be
1780 * shutdown. So return true if any Radio is available.
1781 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1785 Phone phone = PhoneFactory.getPhone(i);
1786 if (phone != null && phone.isRadioAvailable()) return true;
1787 }
1788 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1789 return false;
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 }
1794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 enforceModifyPermission();
1798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 logv("Shutting down Phone " + i);
1803 shutdownRadioUsingPhoneId(i);
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808 }
1809
1810 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 Phone phone = PhoneFactory.getPhone(phoneId);
1812 if (phone != null && phone.isRadioAvailable()) {
1813 phone.shutdownRadio();
1814 }
1815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1823 if (defaultPhone != null) {
1824 defaultPhone.setRadioPower(turnOn);
1825 return true;
1826 } else {
1827 loge("There's no default phone.");
1828 return false;
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001832 }
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone != null) {
1842 phone.setRadioPower(turnOn);
1843 return true;
1844 } else {
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Wink Saville36469e72014-06-11 15:17:00 -07001852 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 public boolean enableDataConnectivity() {
1855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856
1857 final long identity = Binder.clearCallingIdentity();
1858 try {
1859 int subId = mSubscriptionController.getDefaultDataSubId();
1860 final Phone phone = getPhone(subId);
1861 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001862 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 return true;
1864 } else {
1865 return false;
1866 }
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Wink Saville36469e72014-06-11 15:17:00 -07001872 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public boolean disableDataConnectivity() {
1875 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 int subId = mSubscriptionController.getDefaultDataSubId();
1880 final Phone phone = getPhone(subId);
1881 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001882 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 return true;
1884 } else {
1885 return false;
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001893 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001898 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001908 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
pkanwarae03a6b2016-11-06 20:37:09 -08001911 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 enforceCallPermission();
1913
1914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1917 return;
1918 }
1919 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1920 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
pkanwar32d516d2016-10-14 19:37:38 -07001924 };
1925
Wink Savilleb564aae2014-10-23 10:18:09 -07001926 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return false;
1933 }
1934 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001941 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001944 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 Phone phone = PhoneFactory.getPhone(slotIndex);
1948 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1949 PhoneConstantConversions.convertCallState(phone.getState());
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001956 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1958 }
1959
1960 @Override
1961 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 if (phone != null) {
1966 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1967 } else {
1968 return PhoneConstantConversions.convertDataState(
1969 PhoneConstants.DataState.DISCONNECTED);
1970 }
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001977 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1979 }
1980
1981 @Override
1982 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 if (phone != null) {
1987 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1988 } else {
1989 return TelephonyManager.DATA_ACTIVITY_NONE;
1990 }
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
1996 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08001997 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001998 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001999 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002000
2001 LocationAccessPolicy.LocationPermissionResult locationResult =
2002 LocationAccessPolicy.checkLocationPermission(mApp,
2003 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2004 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002005 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002006 .setCallingPid(Binder.getCallingPid())
2007 .setCallingUid(Binder.getCallingUid())
2008 .setMethod("getCellLocation")
2009 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2010 .build());
2011 switch (locationResult) {
2012 case DENIED_HARD:
2013 throw new SecurityException("Not allowed to access cell location");
2014 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002015 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2016 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002023 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002024 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Svetoslav64fad262015-04-14 14:35:21 -07002028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002031 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2032 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002033 if (!TextUtils.isEmpty(callingPackage)) {
2034 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2036 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002037 return "";
2038 }
2039 }
2040
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002041 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2042 // registered cell info, so return a NULL country instead.
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002045 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2046 // Get default phone in this case.
2047 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2048 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002050 // Todo: fix this when we can get the actual cellular network info when the device
2051 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002053 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2054 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 return "";
2056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 Phone phone = PhoneFactory.getPhone(phoneId);
2058 if (phone != null) {
2059 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002060 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 if (sst != null) {
2062 LocaleTracker lt = sst.getLocaleTracker();
2063 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002064 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2065 return lt.getCurrentCountry();
2066 } else if (emergencyNumberTracker != null) {
2067 return emergencyNumberTracker.getEmergencyCountryIso();
2068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069 }
2070 }
2071 }
2072 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 }
2077
2078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002080 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002081 }
2082
Sanket Padawe356d7632015-06-22 14:03:32 -07002083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002084 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mApp.enforceCallingOrSelfPermission(
2086 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 final Phone phone = getPhone(subId);
2091 if (phone != null) {
2092 phone.enableLocationUpdates();
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 @Override
2100 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002101 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002102 }
2103
Sanket Padawe356d7632015-06-22 14:03:32 -07002104 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002105 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 mApp.enforceCallingOrSelfPermission(
2107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.disableLocationUpdates();
2114 }
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 /**
2121 * Returns the target SDK version number for a given package name.
2122 *
Nathan Haroldec184742019-07-10 17:04:16 -07002123 * This call MUST be invoked before clearing the calling UID.
2124 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 * @return target SDK if the package is found or INT_MAX.
2126 */
2127 private int getTargetSdk(String packageName) {
2128 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002129 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002130 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002131 if (ai != null) return ai.targetSdkVersion;
2132 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002133 loge("Failed to get package info for pkg="
2134 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 }
2136 return Integer.MAX_VALUE;
2137 }
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 @Override
2140 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002141 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2142 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002156 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002180 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2225 String callingFeatureId) {
2226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2227 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 }
2229
2230 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002231 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2232 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002233 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002234 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002235 }
2236
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002237 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2238 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002239 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002241
2242 LocationAccessPolicy.LocationPermissionResult locationResult =
2243 LocationAccessPolicy.checkLocationPermission(mApp,
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002247 .setCallingPid(Binder.getCallingPid())
2248 .setCallingUid(Binder.getCallingUid())
2249 .setMethod("requestCellInfoUpdate")
2250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2251 .build());
2252 switch (locationResult) {
2253 case DENIED_HARD:
2254 throw new SecurityException("Not allowed to access cell info");
2255 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002256 try {
2257 cb.onCellInfo(new ArrayList<CellInfo>());
2258 } catch (RemoteException re) {
2259 // Drop without consequences
2260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 }
2263
Nathan Harolda939a962019-05-09 10:13:47 -07002264
2265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2267
2268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2269 }
2270
2271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Shishir Agrawala9f32182016-04-12 12:00:16 -07002284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 Phone phone = PhoneFactory.getPhone(slotIndex);
2287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002288 return null;
2289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 return null;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return phone.getImei();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 }
2303
2304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002305 public String getTypeAllocationCodeForSlot(int slotIndex) {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 String tac = null;
2308 if (phone != null) {
2309 String imei = phone.getImei();
2310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2311 }
2312 return tac;
2313 }
2314
2315 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002316 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002319 return null;
2320 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002323 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002324 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return phone.getMeid();
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Jack Yu2af8d712017-03-15 17:14:14 -07002334 }
2335
2336 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002337 public String getManufacturerCodeForSlot(int slotIndex) {
2338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 String manufacturerCode = null;
2340 if (phone != null) {
2341 String meid = phone.getMeid();
2342 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2343 }
2344 return manufacturerCode;
2345 }
2346
2347 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002348 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2349 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 Phone phone = PhoneFactory.getPhone(slotIndex);
2351 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 return null;
2353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 int subId = phone.getSubId();
2355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002356 mApp, subId, callingPackage, callingFeatureId,
2357 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 return null;
2359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 return phone.getDeviceSvn();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002367 }
2368
fionaxu43304da2017-11-27 22:51:16 -08002369 @Override
2370 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
fionaxu43304da2017-11-27 22:51:16 -08002378 }
2379
2380 @Override
2381 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 return phone == null ? null : phone.getCarrierName();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
fionaxu43304da2017-11-27 22:51:16 -08002389 }
2390
calvinpanffe225e2018-11-01 19:43:06 +08002391 @Override
chen xu0026ca62019-03-06 15:28:50 -08002392 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002397 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
2401 }
2402
2403 @Override
chen xu0026ca62019-03-06 15:28:50 -08002404 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002408 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
2412 }
2413
chen xu651eec72018-11-11 19:03:44 -08002414 @Override
chen xu864e11c2018-12-06 22:10:03 -08002415 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2416 if (!isSubscriptionMccMnc) {
2417 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2418 }
chen xu651eec72018-11-11 19:03:44 -08002419 final Phone phone = PhoneFactory.getPhone(slotIndex);
2420 if (phone == null) {
2421 return TelephonyManager.UNKNOWN_CARRIER_ID;
2422 }
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 //
2432 // Internal helper methods.
2433 //
2434
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002435 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2437 *
2438 * @throws SecurityException if the caller does not have the required permission
2439 */
2440 private void enforceModifyPermission() {
2441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2442 }
2443
Shuo Qian3b6ee772019-11-13 17:43:31 -08002444 private void enforceActiveEmergencySessionPermission() {
2445 mApp.enforceCallingOrSelfPermission(
2446 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 /**
2450 * Make sure the caller has the CALL_PHONE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceCallPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2456 }
2457
paulhu5a773602019-08-23 19:17:33 +08002458 private void enforceSettingsPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002460 }
2461
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 private String createTelUrl(String number) {
2463 if (TextUtils.isEmpty(number)) {
2464 return null;
2465 }
2466
Jake Hambye994d462014-02-03 13:10:13 -08002467 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Ihab Awadf9e92732013-12-05 18:02:52 -08002470 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002474 private static void logv(String msg) {
2475 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Ihab Awadf9e92732013-12-05 18:02:52 -08002478 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2480 }
2481
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002484 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002488 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = PhoneFactory.getPhone(slotIndex);
2492 if (phone == null) {
2493 return PhoneConstants.PHONE_TYPE_NONE;
2494 } else {
2495 return phone.getPhoneType();
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
2503 * Returns the CDMA ERI icon index to display
2504 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002506 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2507 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2508 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002512 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002515 mApp, subId, callingPackage, callingFeatureId,
2516 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 return -1;
2518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 return phone.getCdmaEriIconIndex();
2525 } else {
2526 return -1;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
2534 * Returns the CDMA ERI icon mode,
2535 * 0 - ON
2536 * 1 - FLASHING
2537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2540 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002542 }
2543
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002545 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002548 mApp, subId, callingPackage, callingFeatureId,
2549 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return -1;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getCdmaEriIconMode();
2558 } else {
2559 return -1;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
2567 * Returns the CDMA ERI text,
2568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002570 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2571 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002576 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2577 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002579 mApp, subId, callingPackage, callingFeatureId,
2580 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 return phone.getCdmaEriText();
2589 } else {
2590 return null;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
2597 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002598 * Returns the CDMA MDN.
2599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return phone.getLine1Number();
2610 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 }
2617 }
2618
2619 /**
2620 * Returns the CDMA MIN.
2621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2631 return phone.getCdmaMin();
2632 } else {
2633 return null;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002637 }
2638 }
2639
Hall Liud892bec2018-11-30 14:51:45 -08002640 @Override
2641 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2642 INumberVerificationCallback callback, String callingPackage) {
2643 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2644 != PERMISSION_GRANTED) {
2645 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2646 }
2647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2648
2649 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2650 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2651 throw new SecurityException("Calling package must be configured in the device config");
2652 }
2653
2654 if (range == null) {
2655 throw new NullPointerException("Range must be non-null");
2656 }
2657
2658 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002659 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002660
2661 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2662 }
2663
Junda Liuca05d5d2014-08-14 22:36:34 -07002664 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 * Returns true if CDMA provisioning needs to run.
2666 */
2667 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002670 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 * Sets the voice mail number of a given subId.
2678 */
2679 @Override
2680 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2682 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2687 new Pair<String, String>(alphaTag, number), new Integer(subId));
2688 return success;
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002692 }
2693
Ta-wei Yen87c49842016-05-13 21:19:52 -07002694 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002695 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002697 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2698 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 if (!TextUtils.equals(callingPackage, systemDialer)) {
2700 throw new SecurityException("caller must be system dialer");
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2706 if (phoneAccountHandle == null) {
2707 return null;
2708 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002709 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 }
2714
2715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002716 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2717 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002720 mApp, subId, callingPackage, callingFeatureId,
2721 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002722 return null;
2723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002725 final long identity = Binder.clearCallingIdentity();
2726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002727 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002731 }
2732
2733 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002734 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2735 VisualVoicemailSmsFilterSettings settings) {
2736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002758 }
2759
2760 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002761 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2762 String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002775 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002776 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002781 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 }
2786
2787 @Override
2788 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2789 String number, int port, String text, PendingIntent sentIntent) {
2790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002791 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002793 SmsController smsController = PhoneFactory.getSmsController();
2794 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2795 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002796 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002797
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002798 /**
fionaxu0152e512016-11-14 13:36:14 -08002799 * Sets the voice activation state of a given subId.
2800 */
2801 @Override
2802 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2804 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 if (phone != null) {
2810 phone.setVoiceActivationState(activationState);
2811 } else {
2812 loge("setVoiceActivationState fails with invalid subId: " + subId);
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002816 }
2817 }
2818
2819 /**
2820 * Sets the data activation state of a given subId.
2821 */
2822 @Override
2823 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setDataActivationState(activationState);
2832 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002833 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002837 }
2838 }
2839
2840 /**
2841 * Returns the voice activation state of a given subId.
2842 */
2843 @Override
2844 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
fionaxu0152e512016-11-14 13:36:14 -08002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (phone != null) {
2851 return phone.getVoiceActivationState();
2852 } else {
2853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002857 }
2858 }
2859
2860 /**
2861 * Returns the data activation state of a given subId.
2862 */
2863 @Override
2864 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
fionaxu0152e512016-11-14 13:36:14 -08002867 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 if (phone != null) {
2871 return phone.getDataActivationState();
2872 } else {
2873 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002877 }
2878 }
2879
2880 /**
Wink Saville36469e72014-06-11 15:17:00 -07002881 * Returns the unread count of voicemails for a subId
2882 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002884 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2885 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002887 mApp, subId, callingPackage, callingFeatureId,
2888 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002889 return 0;
2890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 return phone.getVoiceMessageCount();
2896 } else {
2897 return 0;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
2904 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002905 * returns true, if the device is in a state where both voice and data
2906 * are supported simultaneously. This can change based on location or network condition.
2907 */
2908 @Override
2909 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002917 }
2918
2919 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002920 * Send the dialer code if called from the current default dialer or the caller has
2921 * carrier privilege.
2922 * @param inputCode The dialer code to send
2923 */
2924 @Override
2925 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002926 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002928 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2929 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002930 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002932 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
fionaxu235cc5e2017-03-06 22:25:57 -08002941 }
2942
Pengquan Menga1bb6272018-09-06 09:59:22 -07002943 @Override
2944 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002945 if (!isActiveSubscription(subId)) {
2946 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2947 }
2948
Pengquan Menga1bb6272018-09-06 09:59:22 -07002949 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2950 }
2951
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002953 public boolean isInEmergencySmsMode() {
2954 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 for (Phone phone : PhoneFactory.getPhones()) {
2958 if (phone.isInEmergencySmsMode()) {
2959 return true;
2960 }
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 return false;
2966 }
2967
2968 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002969 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2970 throws RemoteException {
2971 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2974 "IMS not available on device.");
2975 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 final long token = Binder.clearCallingIdentity();
2977 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002981 } catch (ImsException e) {
2982 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 } finally {
2984 Binder.restoreCallingIdentity(token);
2985 }
2986 }
2987
2988 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002989 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2990 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2993 }
Meng Wangafbc5852019-09-19 17:37:13 -07002994 final long token = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2997 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2998 .removeRegistrationCallbackForSubscription(c, subId);
2999 } catch (ImsException e) {
3000 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3001 + "is inactive, ignoring unregister.");
3002 // If the subscription is no longer active, just return, since the callback
3003 // will already have been removed internally.
3004 } finally {
3005 Binder.restoreCallingIdentity(token);
3006 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 }
3008
Brad Ebingera34a6c22019-10-22 17:36:18 -07003009 /**
3010 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3011 */
3012 @Override
3013 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3014 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3017 "IMS not available on device.");
3018 }
3019 final long token = Binder.clearCallingIdentity();
3020 try {
3021 Phone phone = getPhone(subId);
3022 if (phone == null) {
3023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3024 + subId + "'");
3025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3026 }
3027 phone.getImsRegistrationState(regState -> {
3028 try {
3029 consumer.accept((regState == null)
3030 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3031 } catch (RemoteException e) {
3032 // Ignore if the remote process is no longer available to call back.
3033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3034 }
3035 });
3036 } finally {
3037 Binder.restoreCallingIdentity(token);
3038 }
3039 }
3040
3041 /**
3042 * Get the transport type for the IMS service registration state.
3043 */
3044 @Override
3045 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3046 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3049 "IMS not available on device.");
3050 }
3051 final long token = Binder.clearCallingIdentity();
3052 try {
3053 Phone phone = getPhone(subId);
3054 if (phone == null) {
3055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3056 + subId + "'");
3057 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3058 }
3059 phone.getImsRegistrationTech(regTech -> {
3060 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3061 int regTechConverted = (regTech == null)
3062 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3063 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3064 regTechConverted);
3065 try {
3066 consumer.accept(regTechConverted);
3067 } catch (RemoteException e) {
3068 // Ignore if the remote process is no longer available to call back.
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3070 }
3071 });
3072 } finally {
3073 Binder.restoreCallingIdentity(token);
3074 }
3075 }
3076
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003078 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3079 throws RemoteException {
3080 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003081 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3082 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3083 "IMS not available on device.");
3084 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3086 final long token = Binder.clearCallingIdentity();
3087 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003090 } catch (ImsException e) {
3091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 } finally {
3093 Binder.restoreCallingIdentity(token);
3094 }
3095 }
3096
3097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003098 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3099 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003100 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3101 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3102 }
Meng Wangafbc5852019-09-19 17:37:13 -07003103
3104 final long token = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3107 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003108 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003109 } catch (ImsException e) {
3110 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3111 + "is inactive, ignoring unregister.");
3112 // If the subscription is no longer active, just return, since the callback
3113 // will already have been removed internally.
3114 } finally {
3115 Binder.restoreCallingIdentity(token);
3116 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 }
3118
3119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003120 public boolean isCapable(int subId, int capability, int regTech) {
3121 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3123 final long token = Binder.clearCallingIdentity();
3124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003127 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3129 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003130 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003131 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3132 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 } finally {
3134 Binder.restoreCallingIdentity(token);
3135 }
3136 }
3137
3138 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003139 public boolean isAvailable(int subId, int capability, int regTech) {
3140 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 final long token = Binder.clearCallingIdentity();
3142 try {
3143 Phone phone = getPhone(subId);
3144 if (phone == null) return false;
3145 return phone.isImsCapabilityAvailable(capability, regTech);
3146 } finally {
3147 Binder.restoreCallingIdentity(token);
3148 }
3149 }
3150
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003151 /**
3152 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3153 * subscription.
3154 * @param subId The subscription to use to check the configuration.
3155 * @param callback The callback that will be used to send the result.
3156 * @param capability The MmTelFeature capability that will be used to send the result.
3157 * @param transportType The transport type of the MmTelFeature capability.
3158 */
3159 @Override
3160 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3161 int transportType) {
3162 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3165 "IMS not available on device.");
3166 }
3167 final long token = Binder.clearCallingIdentity();
3168 try {
3169 int slotId = getSlotIndex(subId);
3170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3171 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3172 + subId + "'");
3173 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3174 }
3175 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3176 transportType, aBoolean -> {
3177 try {
3178 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3179 } catch (RemoteException e) {
3180 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3181 + "running. Ignore");
3182 }
3183 });
3184 } finally {
3185 Binder.restoreCallingIdentity(token);
3186 }
3187 }
3188
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 @Override
3190 public boolean isAdvancedCallingSettingEnabled(int subId) {
3191 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3193 final long token = Binder.clearCallingIdentity();
3194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003195 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003197 } catch (ImsException e) {
3198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 } finally {
3200 Binder.restoreCallingIdentity(token);
3201 }
3202 }
3203
3204 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003205 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003207 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003213 } catch (ImsException e) {
3214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
3220 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003221 public boolean isVtSettingEnabled(int subId) {
3222 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003226 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003235 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003237 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003241 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
3250 public boolean isVoWiFiSettingEnabled(int subId) {
3251 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003257 } catch (ImsException e) {
3258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003265 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003267 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
3273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
3280 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3281 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003287 } catch (ImsException e) {
3288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
3292 }
3293
3294 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003295 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003297 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3313 "setVoWiFiNonPersistent");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003318 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public int getVoWiFiModeSetting(int subId) {
3328 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003334 } catch (ImsException e) {
3335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
3342 public void setVoWiFiModeSetting(int subId, int mode) {
3343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3344 "setVoWiFiModeSetting");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public int getVoWiFiRoamingModeSetting(int subId) {
3359 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003365 } catch (ImsException e) {
3366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
3372 @Override
3373 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3375 "setVoWiFiRoamingModeSetting");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3391 "setRttCapabilityEnabled");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3396 } catch (ImsException e) {
3397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
3403 @Override
3404 public boolean isTtyOverVolteEnabled(int subId) {
3405 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (ImsException e) {
3412 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 @Override
3419 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3420 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003426 } catch (ImsException e) {
3427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432
3433 @Override
3434 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3435 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3436 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3438 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3439 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 try {
3441 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003443 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003445 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3446 + "is inactive, ignoring unregister.");
3447 // If the subscription is no longer active, just return, since the callback will already
3448 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
3452 }
3453
3454 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3456 boolean isProvisioned) {
3457 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3458 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3459 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3460 }
3461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3462 "setProvisioningStatusForCapability");
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3466 Phone phone = getPhone(subId);
3467 if (phone == null) {
3468 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3469 + subId);
3470 return;
3471 }
3472 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3473 return;
3474 }
3475
3476 // this capability requires provisioning, route to the correct API.
3477 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3478 switch (capability) {
3479 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3480 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3481 ims.setVolteProvisioned(isProvisioned);
3482 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3483 ims.setWfcProvisioned(isProvisioned);
3484 }
3485 break;
3486 }
3487 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3488 // There is currently no difference in VT provisioning type.
3489 ims.setVtProvisioned(isProvisioned);
3490 break;
3491 }
3492 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3493 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3494 // change the capability of the feature instead if needed.
3495 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3496 == isProvisioned) {
3497 // No change in provisioning.
3498 return;
3499 }
3500 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3501 try {
3502 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003503 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3505 + ", Exception" + e.getMessage());
3506 }
3507 break;
3508 }
3509 default: {
3510 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3511 + capability + "', which does not require provisioning.");
3512 }
3513 }
3514
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
3518 }
3519
3520 @Override
3521 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3522 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3523 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3524 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3525 }
3526 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3530 Phone phone = getPhone(subId);
3531 if (phone == null) {
3532 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3533 + subId);
3534 // We will fail with "true" as the provisioning status because this is the default
3535 // if we do not require provisioning.
3536 return true;
3537 }
3538
3539 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3540 return true;
3541 }
3542
3543 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3544 switch (capability) {
3545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3546 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3547 return ims.isVolteProvisionedOnDevice();
3548 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3549 return ims.isWfcProvisionedOnDevice();
3550 }
3551 // This should never happen, since we are checking tech above to make sure it
3552 // is either LTE or IWLAN.
3553 throw new IllegalArgumentException("Invalid radio technology for voice "
3554 + "capability.");
3555 }
3556 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3557 // There is currently no difference in VT provisioning type.
3558 return ims.isVtProvisionedOnDevice();
3559 }
3560 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3561 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3562 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3563 }
3564 default: {
3565 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3566 + capability + "', which does not require provisioning.");
3567 }
3568 }
3569
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
3572 }
3573 }
3574
3575 @Override
3576 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3577 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3578 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3579 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3580 }
3581 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3582 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3583 return (provisionedBits & capability) > 0;
3584 }
3585
3586 @Override
3587 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3588 boolean isProvisioned) {
3589 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3590 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3591 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3592 }
3593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3594 "setProvisioningStatusForCapability");
3595 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3596 // If the current provisioning status for capability already matches isProvisioned,
3597 // do nothing.
3598 if (((provisionedBits & capability) > 0) == isProvisioned) {
3599 return;
3600 }
3601 if (isProvisioned) {
3602 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3603 } else {
3604 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3605 }
3606 }
3607
3608 /**
3609 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3610 * technology. The bitfield should mirror the bitfield defined by
3611 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3612 */
3613 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3614 String key = getMmTelProvisioningKey(subId, tech);
3615 // Default is no capabilities are provisioned.
3616 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3617 }
3618
3619 /**
3620 * Sets the MmTel capability provisioning bitfield (defined by
3621 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3622 * technology specified.
3623 *
3624 * Note: This is a synchronous command and should not be called on UI thread.
3625 */
3626 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3627 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3628 String key = getMmTelProvisioningKey(subId, tech);
3629 editor.putInt(key, newField);
3630 editor.commit();
3631 }
3632
3633 private static String getMmTelProvisioningKey(int subId, int tech) {
3634 // resulting key is provision_ims_mmtel_{subId}_{tech}
3635 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3636 }
3637
3638 /**
3639 * Query CarrierConfig to see if the specified capability requires provisioning for the
3640 * carrier associated with the subscription id.
3641 */
3642 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3643 int capability) {
3644 CarrierConfigManager configManager = new CarrierConfigManager(context);
3645 PersistableBundle c = configManager.getConfigForSubId(subId);
3646 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003647 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003648 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3649 false);
3650 boolean requireVoiceVtProvisioning = c.getBoolean(
3651 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3652
3653 // First check to make sure that the capability requires provisioning.
3654 switch (capability) {
3655 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3656 // intentional fallthrough
3657 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3658 if (requireVoiceVtProvisioning) {
3659 // Voice and Video requires provisioning
3660 return true;
3661 }
3662 break;
3663 }
3664 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3665 if (requireUtProvisioning) {
3666 // UT requires provisioning
3667 return true;
3668 }
3669 break;
3670 }
3671 }
3672 return false;
3673 }
3674
3675 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003676 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3678 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3679 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 enforceReadPrivilegedPermission("getImsProvisioningInt");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003684 int slotId = getSlotIndex(subId);
3685 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3686 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3687 + subId + "' for key:" + key);
3688 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3689 }
3690 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003691 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003692 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3693 + subId + "' for key:" + key);
3694 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
3700 @Override
3701 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3703 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3704 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 enforceReadPrivilegedPermission("getImsProvisioningString");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 int slotId = getSlotIndex(subId);
3710 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3711 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3712 + subId + "' for key:" + key);
3713 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3714 }
3715 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003717 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3718 + subId + "' for key:" + key);
3719 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
3725 @Override
3726 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003727 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3728 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3729 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3731 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003735 int slotId = getSlotIndex(subId);
3736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3737 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3738 + subId + "' for key:" + key);
3739 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3740 }
3741 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3744 + "' for key:" + key);
3745 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
3751 @Override
3752 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3754 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3755 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3757 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003761 int slotId = getSlotIndex(subId);
3762 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3763 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3764 + subId + "' for key:" + key);
3765 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3766 }
3767 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003768 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3770 + "' for key:" + key);
3771 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
3775 }
3776
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003777 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 int slotId = SubscriptionManager.getSlotIndex(subId);
3779 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3781 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 }
3783 return slotId;
3784 }
3785
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 private int getSlotIndex(int subId) {
3787 int slotId = SubscriptionManager.getSlotIndex(subId);
3788 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3789 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3790 }
3791 return slotId;
3792 }
3793
Wink Saville36469e72014-06-11 15:17:00 -07003794 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003795 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003796 */
3797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003798 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3799 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003800 final int targetSdk = getTargetSdk(callingPackage);
3801 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003802 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003803 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003804 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003805 mApp, subId, callingPackage, callingFeatureId,
3806 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003807 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3808 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 if (phone != null) {
3814 return phone.getServiceState().getDataNetworkType();
3815 } else {
3816 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003821 }
3822
3823 /**
3824 * Returns the data network type
3825 */
3826 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003827 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3828 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3829 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003830 }
3831
3832 /**
3833 * Returns the data network type for a subId
3834 */
3835 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003836 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3837 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003839 mApp, subId, callingPackage, callingFeatureId,
3840 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003841 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3842 }
3843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 final Phone phone = getPhone(subId);
3847 if (phone != null) {
3848 return phone.getServiceState().getDataNetworkType();
3849 } else {
3850 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3851 }
3852 } finally {
3853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 }
3856
3857 /**
Wink Saville36469e72014-06-11 15:17:00 -07003858 * Returns the Voice network type for a subId
3859 */
3860 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003861 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3862 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003864 mApp, subId, callingPackage, callingFeatureId,
3865 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003866 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3867 }
3868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 return phone.getServiceState().getVoiceNetworkType();
3874 } else {
3875 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 }
3881
3882 /**
3883 * @return true if a ICC card is present
3884 */
3885 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003886 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003887 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3888 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003889 }
3890
3891 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003892 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003893 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003894 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003895 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 final Phone phone = PhoneFactory.getPhone(slotIndex);
3899 if (phone != null) {
3900 return phone.getIccCard().hasIccCard();
3901 } else {
3902 return false;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003907 }
3908
3909 /**
3910 * Return if the current radio is LTE on CDMA. This
3911 * is a tri-state return value as for a period of time
3912 * the mode may be unknown.
3913 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003914 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003915 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003916 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3920 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3921 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003922 }
3923
Sanket Padawe356d7632015-06-22 14:03:32 -07003924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003925 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3926 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003928 mApp, subId, callingPackage, callingFeatureId,
3929 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003930 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3931 }
3932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 final Phone phone = getPhone(subId);
3936 if (phone == null) {
3937 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3938 } else {
3939 return phone.getLteOnCdmaMode();
3940 }
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 }
Wink Saville36469e72014-06-11 15:17:00 -07003944 }
3945
Wink Saville36469e72014-06-11 15:17:00 -07003946 /**
3947 * {@hide}
3948 * Returns Default subId, 0 in the case of single standby.
3949 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003950 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003951 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003952 }
3953
Shishir Agrawala9f32182016-04-12 12:00:16 -07003954 private int getSlotForDefaultSubscription() {
3955 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3956 }
3957
Wink Savilleb564aae2014-10-23 10:18:09 -07003958 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003959 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003960 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003961
Pengquan Menge92a50d2018-09-21 15:54:48 -07003962 private boolean isActiveSubscription(int subId) {
3963 return mSubscriptionController.isActiveSubId(subId);
3964 }
3965
Ihab Awadf2177b72013-11-25 13:33:23 -08003966 /**
3967 * @see android.telephony.TelephonyManager.WifiCallingChoices
3968 */
3969 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 final long identity = Binder.clearCallingIdentity();
3971 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3974 getWhenToMakeWifiCallsDefaultPreference());
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003978 }
3979
3980 /**
3981 * @see android.telephony.TelephonyManager.WifiCallingChoices
3982 */
3983 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003992 }
3993
Sailesh Nepald1e68152013-12-12 19:08:02 -08003994 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003995 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003996 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003997 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003998
Jordan Liu4c733742019-02-28 12:03:40 -08003999 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4000 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4001 if (phoneId == -1) {
4002 throw new IllegalArgumentException("Given slot index: " + slotIndex
4003 + " does not correspond to an active phone");
4004 }
4005 return PhoneFactory.getPhone(phoneId);
4006 }
4007
Shishir Agrawal566b7612013-10-28 14:41:00 -07004008 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004009 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4010 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4012 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004014 if (DBG) {
4015 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4016 }
4017 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4018 p2);
4019 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004020
Jordan Liu4c733742019-02-28 12:03:40 -08004021
4022 @Override
4023 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4024 int slotIndex, String callingPackage, String aid, int p2) {
4025 enforceModifyPermission();
4026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4027 if (DBG) {
4028 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4029 }
4030 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4031 callingPackage, aid, p2);
4032 }
4033
4034 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4035 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 if (TextUtils.equals(ISDR_AID, aid)) {
4039 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4041 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 if (bestComponent == null
4043 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4044 loge("The calling package is not allowed to access ISD-R.");
4045 throw new SecurityException(
4046 "The calling package is not allowed to access ISD-R.");
4047 }
Derek Tan740e1672017-06-27 14:56:27 -07004048 }
Derek Tan740e1672017-06-27 14:56:27 -07004049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004051 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4052 null /* workSource */);
4053 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 return response;
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004058 }
4059
4060 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004061 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4063 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004064 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4065 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4066 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004067
Jordan Liu4c733742019-02-28 12:03:40 -08004068 @Override
4069 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4070 enforceModifyPermission();
4071 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4072 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4073 channel);
4074 }
4075
4076 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077 final long identity = Binder.clearCallingIdentity();
4078 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 if (channel < 0) {
4080 return false;
4081 }
Jordan Liu4c733742019-02-28 12:03:40 -08004082 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4083 null /* workSource */);
4084 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 return success;
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004088 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004089 }
4090
4091 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004092 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004093 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4095 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004096 if (DBG) {
4097 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4098 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4099 + p3 + " data=" + data);
4100 }
4101 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4102 command, p1, p2, p3, data);
4103 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004104
Jordan Liu4c733742019-02-28 12:03:40 -08004105 @Override
4106 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4107 int command, int p1, int p2, int p3, String data) {
4108 enforceModifyPermission();
4109 if (DBG) {
4110 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4111 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4112 + p3 + " data=" + data);
4113 }
4114 return iccTransmitApduLogicalChannelWithPermission(
4115 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4116 data);
4117 }
4118
4119 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4120 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 final long identity = Binder.clearCallingIdentity();
4122 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004123 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 return "";
4125 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004128 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4129 null /* workSource */);
4130 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 // Append the returned status code to the end of the response payload.
4133 String s = Integer.toHexString(
4134 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4135 if (response.payload != null) {
4136 s = IccUtils.bytesToHexString(response.payload) + s;
4137 }
4138 return s;
4139 } finally {
4140 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004142 }
Jake Hambye994d462014-02-03 13:10:13 -08004143
Evan Charltonc66da362014-05-16 14:06:40 -07004144 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004145 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4146 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4148 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004150 if (DBG) {
4151 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4152 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4153 }
4154 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4155 cla, command, p1, p2, p3, data);
4156 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004157
Jordan Liu4c733742019-02-28 12:03:40 -08004158 @Override
4159 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4160 int command, int p1, int p2, int p3, String data) {
4161 enforceModifyPermission();
4162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4163 if (DBG) {
4164 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4165 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4166 + " data=" + data);
4167 }
4168
4169 return iccTransmitApduBasicChannelWithPermission(
4170 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4171 p2, p3, data);
4172 }
4173
4174 // open APDU basic channel assuming the caller has sufficient permissions
4175 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4176 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4180 && TextUtils.equals(ISDR_AID, data)) {
4181 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004182 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4183 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 if (bestComponent == null
4185 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4186 loge("The calling package is not allowed to select ISD-R.");
4187 throw new SecurityException(
4188 "The calling package is not allowed to select ISD-R.");
4189 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004190 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004193 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4194 null /* workSource */);
4195 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 // Append the returned status code to the end of the response payload.
4198 String s = Integer.toHexString(
4199 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4200 if (response.payload != null) {
4201 s = IccUtils.bytesToHexString(response.payload) + s;
4202 }
4203 return s;
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004206 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004207 }
4208
4209 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004210 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004211 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4213 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (DBG) {
4218 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4219 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4220 }
4221
4222 IccIoResult response =
4223 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4224 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4225 subId);
4226
4227 if (DBG) {
4228 log("Exchange SIM_IO [R]" + response);
4229 }
4230
4231 byte[] result = null;
4232 int length = 2;
4233 if (response.payload != null) {
4234 length = 2 + response.payload.length;
4235 result = new byte[length];
4236 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4237 } else {
4238 result = new byte[length];
4239 }
4240
4241 result[length - 1] = (byte) response.sw2;
4242 result[length - 2] = (byte) response.sw1;
4243 return result;
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004246 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004247 }
4248
Nathan Haroldb3014052017-01-25 15:57:32 -08004249 /**
4250 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4251 * on a particular subscription
4252 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004253 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4254 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004256 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004257 return null;
4258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259
4260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 if (appType != TelephonyManager.APPTYPE_USIM
4263 && appType != TelephonyManager.APPTYPE_SIM) {
4264 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4265 return null;
4266 }
4267 Object response = sendRequest(
4268 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4269 if (response instanceof String[]) {
4270 return (String[]) response;
4271 }
yincheng zhao2737e882019-09-06 17:06:54 -07004272 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004274 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004277 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004278 }
4279
yincheng zhao2737e882019-09-06 17:06:54 -07004280 /**
4281 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4282 * subscription.
4283 *
4284 * @param subId the id of the subscription.
4285 * @param appType the uicc app type, must be USIM or SIM.
4286 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4287 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004288 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004289 * @return number of fplmns that is successfully written to the SIM.
4290 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004291 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4292 String callingFeatureId) {
4293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4294 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004295 if (DBG) logv("no permissions for setForbiddenplmns");
4296 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4297 }
4298 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4299 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4300 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4301 }
4302 if (fplmns == null) {
4303 throw new IllegalArgumentException("Fplmn List provided is null");
4304 }
4305 for (String fplmn : fplmns) {
4306 if (!CellIdentity.isValidPlmn(fplmn)) {
4307 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4308 }
4309 }
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 Object response = sendRequest(
4313 CMD_SET_FORBIDDEN_PLMNS,
4314 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4315 subId);
4316 return (int) response;
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
4320 }
4321
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004323 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4325 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4330 if (response.payload == null) {
4331 return "";
4332 }
Evan Charltonc66da362014-05-16 14:06:40 -07004333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 // Append the returned status code to the end of the response payload.
4335 String s = Integer.toHexString(
4336 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4337 s = IccUtils.bytesToHexString(response.payload) + s;
4338 return s;
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Evan Charltonc66da362014-05-16 14:06:40 -07004342 }
4343
Jake Hambye994d462014-02-03 13:10:13 -08004344 /**
4345 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4346 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4347 *
4348 * @param itemID the ID of the item to read
4349 * @return the NV item as a String, or null on error.
4350 */
4351 @Override
4352 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4355 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004360 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4362 return value;
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
Jake Hambye994d462014-02-03 13:10:13 -08004366 }
4367
4368 /**
4369 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4370 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4371 *
4372 * @param itemID the ID of the item to read
4373 * @param itemValue the value to write, as a String
4374 * @return true on success; false on any failure
4375 */
4376 @Override
4377 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004378 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4380 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381
4382 final long identity = Binder.clearCallingIdentity();
4383 try {
4384 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4385 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004386 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4388 return success;
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
4391 }
Jake Hambye994d462014-02-03 13:10:13 -08004392 }
4393
4394 /**
4395 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4396 * Used for device configuration by some CDMA operators.
4397 *
4398 * @param preferredRoamingList byte array containing the new PRL
4399 * @return true on success; false on any failure
4400 */
4401 @Override
4402 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
4406 final long identity = Binder.clearCallingIdentity();
4407 try {
4408 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4409 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4410 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4411 return success;
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
Jake Hambye994d462014-02-03 13:10:13 -08004415 }
4416
4417 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004418 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004419 * Used for device configuration by some CDMA operators.
4420 *
chen xu6dac5ab2018-10-26 17:39:23 -07004421 * @param slotIndex - device slot.
4422 *
Jake Hambye994d462014-02-03 13:10:13 -08004423 * @return true on success; false on any failure
4424 */
4425 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004426 public boolean resetModemConfig(int slotIndex) {
4427 Phone phone = PhoneFactory.getPhone(slotIndex);
4428 if (phone != null) {
4429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4430 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431
chen xu6dac5ab2018-10-26 17:39:23 -07004432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4435 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4436 return success;
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 }
chen xu6dac5ab2018-10-26 17:39:23 -07004441 return false;
4442 }
4443
4444 /**
4445 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4446 *
4447 * @param slotIndex - device slot.
4448 *
4449 * @return true on success; false on any failure
4450 */
4451 @Override
4452 public boolean rebootModem(int slotIndex) {
4453 Phone phone = PhoneFactory.getPhone(slotIndex);
4454 if (phone != null) {
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4456 mApp, phone.getSubId(), "rebootModem");
4457
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4461 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4462 return success;
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004468 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004469
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004470 public String[] getPcscfAddress(String apnType, String callingPackage,
4471 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004472 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4474 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004475 return new String[0];
4476 }
4477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004480 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Wink Saville36469e72014-06-11 15:17:00 -07004484 }
4485
Brad Ebinger51f743a2017-01-23 13:50:20 -08004486 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004487 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4488 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004489 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004490 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004495 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004496 // may happen if the device does not support IMS.
4497 return;
4498 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004499 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004503 }
4504
4505 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004506 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4507 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004508 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004509 public void disableIms(int slotId) {
4510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004514 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004515 // may happen if the device does not support IMS.
4516 return;
4517 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004518 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004522 }
4523
4524 /**
4525 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4526 * feature or {@link null} if the service is not available. If the feature is available, the
4527 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4528 */
4529 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004530 IImsServiceFeatureCallback callback) {
4531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004535 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004536 // may happen if the device does not support IMS.
4537 return null;
4538 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004539 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004543 }
4544
4545 /**
4546 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4547 * feature during emergency calling or {@link null} if the service is not available. If the
4548 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4549 * listener for feature updates.
4550 */
4551 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004556 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004557 // may happen if the device does not support IMS.
4558 return null;
4559 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004560 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004564 }
4565
Brad Ebinger5f64b052017-12-14 14:26:15 -08004566 /**
4567 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004568 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004569 */
4570 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004575 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004576 // may happen if the device does not support IMS.
4577 return null;
4578 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004579 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004583 }
4584
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004585 /**
4586 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004587 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004588 */
4589 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591
4592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004594 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004595 // may happen if the device does not support IMS.
4596 return null;
4597 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004598 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 }
4603
Brad Ebinger884c07b2018-02-15 16:17:40 -08004604 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004605 * Sets the ImsService Package Name that Telephony will bind to.
4606 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004607 * @param slotIndex the slot ID that the ImsService should bind for.
4608 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004609 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004610 * @param featureTypes An integer array of feature types associated with a packageName.
4611 * @param packageName The name of the package that the current configuration will be replaced
4612 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004613 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004614 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004615 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4616 int[] featureTypes, String packageName) {
4617 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4620 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004621 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004625 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004626 // may happen if the device does not support IMS.
4627 return false;
4628 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004629 Map<Integer, String> featureConfig = new HashMap<>();
4630 for (int featureType : featureTypes) {
4631 featureConfig.put(featureType, packageName);
4632 }
4633 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4634 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004638 }
4639
4640 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004641 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004642 *
4643 * @param slotId The slot that the ImsService is associated with.
4644 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4645 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004646 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004647 * @return the package name of the ImsService configuration.
4648 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004649 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4650 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004651 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004652 TelephonyPermissions
4653 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4654 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4655 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004659 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004660 // may happen if the device does not support IMS.
4661 return "";
4662 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004663 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004664 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4665 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004669 }
4670
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004671 /**
4672 * Get the MmTelFeature state associated with the requested subscription id.
4673 * @param subId The subscription that the MmTelFeature is associated with.
4674 * @param callback A callback with an integer containing the
4675 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4676 */
4677 @Override
4678 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4679 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4680 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4682 "IMS not available on device.");
4683 }
4684 final long token = Binder.clearCallingIdentity();
4685 try {
4686 int slotId = getSlotIndex(subId);
4687 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4688 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4689 + subId + "'");
4690 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4691 }
4692 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4693 try {
4694 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4695 } catch (RemoteException e) {
4696 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4697 + "Ignore");
4698 }
4699 });
4700 } finally {
4701 Binder.restoreCallingIdentity(token);
4702 }
4703 }
4704
Wink Saville36469e72014-06-11 15:17:00 -07004705 public void setImsRegistrationState(boolean registered) {
4706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004710 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
Wink Saville36469e72014-06-11 15:17:00 -07004714 }
4715
4716 /**
Stuart Scott54788802015-03-30 13:18:01 -07004717 * Set the network selection mode to automatic.
4718 *
4719 */
4720 @Override
4721 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4723 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724
Pengquan Menge92a50d2018-09-21 15:54:48 -07004725 if (!isActiveSubscription(subId)) {
4726 return;
4727 }
4728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4732 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
Stuart Scott54788802015-03-30 13:18:01 -07004736 }
4737
Pengquan Mengea84e042018-09-20 14:57:26 -07004738 /**
4739 * Ask the radio to connect to the input network and change selection mode to manual.
4740 *
4741 * @param subId the id of the subscription.
4742 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4743 * the operator to attach to.
4744 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4745 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4746 * normal network selection next time.
4747 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004748 */
4749 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004750 public boolean setNetworkSelectionModeManual(
4751 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4753 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004754
4755 if (!isActiveSubscription(subId)) {
4756 return false;
4757 }
4758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004761 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004763 if (DBG) {
4764 log("setNetworkSelectionModeManual: subId: " + subId
4765 + " operator: " + operatorInfo);
4766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004771 }
4772
4773 /**
4774 * Scans for available networks.
4775 */
4776 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004777 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4780 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004781 LocationAccessPolicy.LocationPermissionResult locationResult =
4782 LocationAccessPolicy.checkLocationPermission(mApp,
4783 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4784 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004785 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004786 .setCallingPid(Binder.getCallingPid())
4787 .setCallingUid(Binder.getCallingUid())
4788 .setMethod("getCellNetworkScanResults")
4789 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4790 .build());
4791 switch (locationResult) {
4792 case DENIED_HARD:
4793 throw new SecurityException("Not allowed to access scan results -- location");
4794 case DENIED_SOFT:
4795 return null;
4796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797
Pengquan Menga1bb6272018-09-06 09:59:22 -07004798 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 try {
4800 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004801 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004806 }
4807
4808 /**
yinxub1bed742017-04-17 11:45:04 -07004809 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004810 *
yinxub1bed742017-04-17 11:45:04 -07004811 * @param subId id of the subscription
4812 * @param request contains the radio access networks with bands/channels to scan
4813 * @param messenger callback messenger for scan results or errors
4814 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004815 * @return the id of the requested scan which can be used to stop the scan.
4816 */
4817 @Override
4818 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004819 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004822 LocationAccessPolicy.LocationPermissionResult locationResult =
4823 LocationAccessPolicy.checkLocationPermission(mApp,
4824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4825 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004826 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004827 .setCallingPid(Binder.getCallingPid())
4828 .setCallingUid(Binder.getCallingUid())
4829 .setMethod("requestNetworkScan")
4830 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4831 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004832 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004833 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004834 if (e != null) {
4835 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4836 throw e;
4837 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004838 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004839 return TelephonyScanManager.INVALID_SCAN_ID;
4840 }
4841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 }
Hall Liu912dfd32019-04-25 14:02:26 -07004843 int callingUid = Binder.getCallingUid();
4844 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 return mNetworkScanRequestTracker.startNetworkScan(
4848 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004849 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
yinxu504e1392017-04-12 16:03:22 -07004853 }
4854
Hall Liub2ac8ef2019-02-28 15:56:23 -08004855 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004856 NetworkScanRequest request, int subId) {
4857 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4858 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4859 boolean hasNetworkScanPermission =
4860 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4861 == PERMISSION_GRANTED;
4862
4863 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4864 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4865 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004866 }
4867
4868 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4869 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004870 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4871 return new SecurityException("Specific channels must not be"
4872 + " scanned without location access.");
4873 }
4874 }
4875 }
4876
Hall Liub2ac8ef2019-02-28 15:56:23 -08004877 return null;
4878 }
4879
yinxu504e1392017-04-12 16:03:22 -07004880 /**
4881 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004882 *
4883 * @param subId id of the subscription
4884 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004885 */
4886 @Override
4887 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4889 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
Hall Liu912dfd32019-04-25 14:02:26 -07004891 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004894 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
yinxu504e1392017-04-12 16:03:22 -07004898 }
4899
4900 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004901 * Get the calculated preferred network type.
4902 * Used for debugging incorrect network type.
4903 *
4904 * @return the preferred network type, defined in RILConstants.java.
4905 */
4906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004907 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004908 final Phone defaultPhone = getDefaultPhone();
4909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004910 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004911 return RILConstants.PREFERRED_NETWORK_MODE;
4912 }
4913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004917 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
Junda Liu84d15a22014-07-02 11:21:04 -07004921 }
4922
4923 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004924 * Get the preferred network type.
4925 * Used for device configuration by some CDMA operators.
4926 *
4927 * @return the preferred network type, defined in RILConstants.java.
4928 */
4929 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004930 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004931 TelephonyPermissions
4932 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4933 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934
4935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 if (DBG) log("getPreferredNetworkType");
4938 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4939 int networkType = (result != null ? result[0] : -1);
4940 if (DBG) log("getPreferredNetworkType: " + networkType);
4941 return networkType;
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004945 }
4946
4947 /**
4948 * Set the preferred network type.
4949 * Used for device configuration by some CDMA operators.
4950 *
4951 * @param networkType the preferred network type, defined in RILConstants.java.
4952 * @return true on success; false on any failure.
4953 */
4954 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004955 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4957 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958
4959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4962 Boolean success = (Boolean) sendRequest(
4963 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4964 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4965 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004966 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4968 }
4969 return success;
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004972 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004973 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004974
4975 /**
Miaoa84611c2019-03-15 09:21:10 +08004976 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004977 *
Miaoa84611c2019-03-15 09:21:10 +08004978 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004979 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004980 * @hide
4981 */
4982 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004983 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004986 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 try {
Miaoa84611c2019-03-15 09:21:10 +08004988 if (phone != null) {
4989 return phone.hasMatchedTetherApnSetting();
4990 } else {
4991 return false;
4992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004995 }
Junda Liu475951f2014-11-07 16:45:03 -08004996 }
4997
4998 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004999 * Set mobile data enabled
5000 * Used by the user through settings etc to turn on/off mobile data
5001 *
5002 * @param enable {@code true} turn turn data on, else {@code false}
5003 */
5004 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005005 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5007 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 int phoneId = mSubscriptionController.getPhoneId(subId);
5012 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5013 Phone phone = PhoneFactory.getPhone(phoneId);
5014 if (phone != null) {
5015 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005016 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005018 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 }
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005022 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005023 }
5024
5025 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005026 * Get the user enabled state of Mobile Data.
5027 *
5028 * TODO: remove and use isUserDataEnabled.
5029 * This can't be removed now because some vendor codes
5030 * calls through ITelephony directly while they should
5031 * use TelephonyManager.
5032 *
5033 * @return true on enabled
5034 */
5035 @Override
5036 public boolean getDataEnabled(int subId) {
5037 return isUserDataEnabled(subId);
5038 }
5039
5040 /**
5041 * Get whether mobile data is enabled per user setting.
5042 *
5043 * There are other factors deciding whether mobile data is actually enabled, but they are
5044 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005045 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005046 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005047 *
5048 * @return {@code true} if data is enabled else {@code false}
5049 */
5050 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005051 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005052 try {
5053 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5054 null);
5055 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5057 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059
5060 final long identity = Binder.clearCallingIdentity();
5061 try {
5062 int phoneId = mSubscriptionController.getPhoneId(subId);
5063 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5064 Phone phone = PhoneFactory.getPhone(phoneId);
5065 if (phone != null) {
5066 boolean retVal = phone.isUserDataEnabled();
5067 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5068 return retVal;
5069 } else {
5070 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5071 return false;
5072 }
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005075 }
5076 }
5077
5078 /**
5079 * Get whether mobile data is enabled.
5080 *
5081 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5082 * whether mobile data is actually enabled.
5083 *
5084 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5085 *
5086 * @return {@code true} if data is enabled else {@code false}
5087 */
5088 @Override
5089 public boolean isDataEnabled(int subId) {
5090 try {
5091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5092 null);
5093 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5095 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097
5098 final long identity = Binder.clearCallingIdentity();
5099 try {
5100 int phoneId = mSubscriptionController.getPhoneId(subId);
5101 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5102 Phone phone = PhoneFactory.getPhone(phoneId);
5103 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005104 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5106 return retVal;
5107 } else {
5108 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5109 return false;
5110 }
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005113 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005114 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005115
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005116 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5117 Phone phone) {
5118 //load access rules from carrier configs, and check those as well: b/139133814
5119 SubscriptionController subController = SubscriptionController.getInstance();
5120 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5121 || subController == null) return privilegeFromSim;
5122
5123 int uid = Binder.getCallingUid();
5124 PackageManager pkgMgr = phone.getContext().getPackageManager();
5125 String[] packages = pkgMgr.getPackagesForUid(uid);
5126
5127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5130 SubscriptionManager subManager = (SubscriptionManager)
5131 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5132 for (String pkg : packages) {
5133 if (subManager.canManageSubscription(subInfo, pkg)) {
5134 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5135 }
5136 }
5137 return privilegeFromSim;
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
5141 }
5142
5143 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5144 String pkgName) {
5145 //load access rules from carrier configs, and check those as well: b/139133814
5146 SubscriptionController subController = SubscriptionController.getInstance();
5147 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5148 || subController == null) return privilegeFromSim;
5149
5150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5153 SubscriptionManager subManager = (SubscriptionManager)
5154 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5155 return subManager.canManageSubscription(subInfo, pkgName)
5156 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
5160 }
5161
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005162 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005163 public int getCarrierPrivilegeStatus(int subId) {
5164 final Phone phone = getPhone(subId);
5165 if (phone == null) {
5166 loge("getCarrierPrivilegeStatus: Invalid subId");
5167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5168 }
5169 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005170 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005171 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005172 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5173 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005174
5175 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5176 card.getCarrierPrivilegeStatusForCurrentTransaction(
5177 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005178 }
Junda Liu29340342014-07-10 15:23:27 -07005179
5180 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005181 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005182 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005183 final Phone phone = getPhone(subId);
5184 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005185 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005186 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5187 }
5188 UiccProfile profile =
5189 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5190 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005191 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005192 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5193 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005194 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005195 profile.getCarrierPrivilegeStatusForUid(
5196 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 }
5198
5199 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005200 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5201 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005202 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005203 }
5204
5205 int phoneId = SubscriptionManager.getPhoneId(subId);
5206 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005207 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005208 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005209 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5210 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005211 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5212 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5213 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005214 }
5215
5216 @Override
5217 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005218 if (TextUtils.isEmpty(pkgName))
5219 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005220 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5221 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5222 UiccCard card = UiccController.getInstance().getUiccCard(i);
5223 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005224 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005225 continue;
5226 }
5227
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005228 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5229 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5230 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005231 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5232 break;
5233 }
5234 }
5235
5236 return result;
Junda Liu29340342014-07-10 15:23:27 -07005237 }
Derek Tan89e89d42014-07-08 17:00:10 -07005238
5239 @Override
Junda Liue64de782015-04-16 17:19:16 -07005240 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5241 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5242 loge("phoneId " + phoneId + " is not valid.");
5243 return null;
5244 }
5245 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005246 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005247 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005248 return null ;
5249 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005250 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005251 }
5252
Amith Yamasani6e118872016-02-19 12:53:51 -08005253 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005254 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005255 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005256 List<String> privilegedPackages = new ArrayList<>();
5257 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005258 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5259 // has UICC in that slot.
5260 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005261 if (card.hasCarrierPrivilegeRules()) {
5262 if (packages == null) {
5263 // Only check packages in user 0 for now
5264 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005265 PackageManager.MATCH_DISABLED_COMPONENTS
5266 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005267 | PackageManager.GET_SIGNING_CERTIFICATES,
5268 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005269 }
5270 for (int p = packages.size() - 1; p >= 0; p--) {
5271 PackageInfo pkgInfo = packages.get(p);
5272 if (pkgInfo != null && pkgInfo.packageName != null
5273 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005274 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005275 privilegedPackages.add(pkgInfo.packageName);
5276 }
5277 }
5278 }
5279 }
5280 return privilegedPackages;
5281 }
5282
chen xuf7e9fe82019-05-09 19:31:02 -07005283 @Override
5284 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005285 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5286
5287 final long identity = Binder.clearCallingIdentity();
5288
chen xuf7e9fe82019-05-09 19:31:02 -07005289 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005290 try {
5291 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5292 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5293 }
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005296 }
5297 return privilegedPackages;
5298 }
5299
Wink Savilleb564aae2014-10-23 10:18:09 -07005300 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005301 final Phone phone = getPhone(subId);
5302 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005303 if (card == null) {
5304 loge("getIccId: No UICC");
5305 return null;
5306 }
5307 String iccId = card.getIccId();
5308 if (TextUtils.isEmpty(iccId)) {
5309 loge("getIccId: ICC ID is null or empty.");
5310 return null;
5311 }
5312 return iccId;
5313 }
5314
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005315 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005316 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5317 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005318 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005319 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 final String iccId = getIccId(subId);
5324 final Phone phone = getPhone(subId);
5325 if (phone == null) {
5326 return false;
5327 }
5328 final String subscriberId = phone.getSubscriberId();
5329
5330 if (DBG_MERGE) {
5331 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5332 + subscriberId + " to " + number);
5333 }
5334
5335 if (TextUtils.isEmpty(iccId)) {
5336 return false;
5337 }
5338
5339 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5340
5341 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5342 if (alphaTag == null) {
5343 editor.remove(alphaTagPrefKey);
5344 } else {
5345 editor.putString(alphaTagPrefKey, alphaTag);
5346 }
5347
5348 // Record both the line number and IMSI for this ICCID, since we need to
5349 // track all merged IMSIs based on line number
5350 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5351 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5352 if (number == null) {
5353 editor.remove(numberPrefKey);
5354 editor.remove(subscriberPrefKey);
5355 } else {
5356 editor.putString(numberPrefKey, number);
5357 editor.putString(subscriberPrefKey, subscriberId);
5358 }
5359
5360 editor.commit();
5361 return true;
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005364 }
Derek Tan7226c842014-07-02 17:42:23 -07005365 }
5366
5367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005368 public String getLine1NumberForDisplay(int subId, String callingPackage,
5369 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005370 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005372 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005373 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005374 return null;
5375 }
Derek Tan97ebb422014-09-05 16:55:38 -07005376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 String iccId = getIccId(subId);
5380 if (iccId != null) {
5381 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5382 if (DBG_MERGE) {
5383 log("getLine1NumberForDisplay returning "
5384 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5385 }
5386 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5389 return null;
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005392 }
Derek Tan7226c842014-07-02 17:42:23 -07005393 }
5394
5395 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005396 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5397 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005399 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005400 return null;
5401 }
Derek Tan97ebb422014-09-05 16:55:38 -07005402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 String iccId = getIccId(subId);
5406 if (iccId != null) {
5407 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5408 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5409 }
5410 return null;
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005413 }
Derek Tan7226c842014-07-02 17:42:23 -07005414 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005415
5416 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005417 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5418 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005419 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5420 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005422 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005423 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005424 return null;
5425 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005426
Jordan Liub49b04b2019-05-06 14:45:15 -07005427 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5428 // the process, where TelephonyManager was instantiated.
5429 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005430 final long identity = Binder.clearCallingIdentity();
5431 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005432 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final TelephonyManager tele = TelephonyManager.from(context);
5434 final SubscriptionManager sub = SubscriptionManager.from(context);
5435
5436 // Figure out what subscribers are currently active
5437 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438
Jordan Liub49b04b2019-05-06 14:45:15 -07005439 // Only consider subs which match the current subId
5440 // This logic can be simplified. See b/131189269 for progress.
5441 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005442 activeSubscriberIds.add(tele.getSubscriberId(subId));
5443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444
5445 // First pass, find a number override for an active subscriber
5446 String mergeNumber = null;
5447 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5448 for (String key : prefs.keySet()) {
5449 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5450 final String subscriberId = (String) prefs.get(key);
5451 if (activeSubscriberIds.contains(subscriberId)) {
5452 final String iccId = key.substring(
5453 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5454 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5455 mergeNumber = (String) prefs.get(numberKey);
5456 if (DBG_MERGE) {
5457 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5458 + " for active subscriber " + subscriberId);
5459 }
5460 if (!TextUtils.isEmpty(mergeNumber)) {
5461 break;
5462 }
5463 }
5464 }
5465 }
5466
5467 // Shortcut when no active merged subscribers
5468 if (TextUtils.isEmpty(mergeNumber)) {
5469 return null;
5470 }
5471
5472 // Second pass, find all subscribers under that line override
5473 final ArraySet<String> result = new ArraySet<>();
5474 for (String key : prefs.keySet()) {
5475 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5476 final String number = (String) prefs.get(key);
5477 if (mergeNumber.equals(number)) {
5478 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5479 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5480 final String subscriberId = (String) prefs.get(subscriberKey);
5481 if (!TextUtils.isEmpty(subscriberId)) {
5482 result.add(subscriberId);
5483 }
5484 }
5485 }
5486 }
5487
5488 final String[] resultArray = result.toArray(new String[result.size()]);
5489 Arrays.sort(resultArray);
5490 if (DBG_MERGE) {
5491 Slog.d(LOG_TAG,
5492 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5493 }
5494 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005497 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005498 }
5499
5500 @Override
zoey chen38003472019-12-13 17:16:31 +08005501 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5502 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005503
5504 final long identity = Binder.clearCallingIdentity();
5505 try {
5506 final TelephonyManager telephonyManager = mApp.getSystemService(
5507 TelephonyManager.class);
5508 String subscriberId = telephonyManager.getSubscriberId(subId);
5509 if (subscriberId == null) {
5510 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005511 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005512 + subId);
5513 }
5514 return null;
5515 }
5516
5517 final SubscriptionInfo info = SubscriptionController.getInstance()
5518 .getSubscriptionInfo(subId);
5519 final ParcelUuid groupUuid = info.getGroupUuid();
5520 // If it doesn't belong to any group, return just subscriberId of itself.
5521 if (groupUuid == null) {
5522 return new String[]{subscriberId};
5523 }
5524
5525 // Get all subscriberIds from the group.
5526 final List<String> mergedSubscriberIds = new ArrayList<>();
5527 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005528 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5529 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005530 for (SubscriptionInfo subInfo : groupInfos) {
5531 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5532 if (subscriberId != null) {
5533 mergedSubscriberIds.add(subscriberId);
5534 }
5535 }
5536
5537 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540
5541 }
5542 }
5543
5544 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005545 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005546 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005547 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 final Phone phone = getPhone(subId);
5552 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005556 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005557
5558 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005559 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005560 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5561 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5563 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 final Phone phone = getPhone(subId);
5568 if (phone == null) {
5569 return false;
5570 }
5571 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5572 cdmaNonRoamingList);
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005575 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005576 }
5577
5578 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005579 @Deprecated
5580 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5581 enforceModifyPermission();
5582
5583 int returnValue = 0;
5584 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005585 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005586 if(result.exception == null) {
5587 if (result.result != null) {
5588 byte[] responseData = (byte[])(result.result);
5589 if(responseData.length > oemResp.length) {
5590 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5591 responseData.length + "bytes. Buffer Size is " +
5592 oemResp.length + "bytes.");
5593 }
5594 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5595 returnValue = responseData.length;
5596 }
5597 } else {
5598 CommandException ex = (CommandException) result.exception;
5599 returnValue = ex.getCommandError().ordinal();
5600 if(returnValue > 0) returnValue *= -1;
5601 }
5602 } catch (RuntimeException e) {
5603 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5604 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5605 if(returnValue > 0) returnValue *= -1;
5606 }
5607
5608 return returnValue;
5609 }
5610
5611 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005612 public void setRadioCapability(RadioAccessFamily[] rafs) {
5613 try {
5614 ProxyController.getInstance().setRadioCapability(rafs);
5615 } catch (RuntimeException e) {
5616 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5617 }
5618 }
5619
5620 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005621 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005622 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005623 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005624 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005625 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 final long identity = Binder.clearCallingIdentity();
5628 try {
chen xub97461a2018-10-26 14:17:57 -07005629 TelephonyPermissions
5630 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5631 mApp, phone.getSubId(), "getRadioAccessFamily");
5632 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
chen xub97461a2018-10-26 14:17:57 -07005636 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005637 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005638
5639 @Override
5640 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005641 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005646 ImsManager.getInstance(defaultPhone.getContext(),
5647 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005651 }
5652
5653 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005654 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005655 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5657 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005658 return false;
5659 }
Svet Ganovb320e182015-04-16 12:30:10 -07005660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 // Check the user preference and the system-level IMS setting. Even if the user has
5664 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5665 // In the long run, we may instead need to check if there exists a connection service
5666 // which can support video calling.
5667 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005668 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 return imsManager.isVtEnabledByPlatform()
5670 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5671 && imsManager.isVtEnabledByUser();
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005675 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005676
Andrew Leea1239f22015-03-02 17:44:07 -08005677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005678 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5679 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005681 mApp, subId, callingPackage, callingFeatureId,
5682 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 return false;
5684 }
5685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 CarrierConfigManager configManager =
5689 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005690 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
Andrew Leea1239f22015-03-02 17:44:07 -08005695 }
5696
5697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005698 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 return false;
5702 }
5703
5704 final long identity = Binder.clearCallingIdentity();
5705 try {
5706 CarrierConfigManager configManager =
5707 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005708 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5710 } finally {
5711 Binder.restoreCallingIdentity(identity);
5712 }
Andrew Leea1239f22015-03-02 17:44:07 -08005713 }
5714
Andrew Lee9431b832015-03-09 18:46:45 -07005715 @Override
5716 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005717 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005718 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005719 }
5720
5721 @Override
5722 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Andrew Lee9431b832015-03-09 18:46:45 -07005729 }
5730
Hall Liuf6668912018-10-31 17:05:23 -07005731 /**
5732 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5733 * support for the feature and device firmware support.
5734 *
5735 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5736 */
5737 @Override
5738 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 final Phone phone = getPhone(subscriptionId);
5741 if (phone == null) {
5742 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5743 return false;
5744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005746 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5748 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005749 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 return isCarrierSupported && isDeviceSupported;
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Hall Liu98187582018-01-22 19:15:32 -08005754 }
5755
Hall Liuf6668912018-10-31 17:05:23 -07005756 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005757 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5758 * RTT setting, will return true if the device and carrier both support RTT.
5759 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005760 */
5761 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005764 boolean isRttSupported = isRttSupported(subscriptionId);
5765 boolean isUserRttSettingOn = Settings.Secure.getInt(
5766 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5767 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5768 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5769 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005773 }
5774
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005775 @Deprecated
5776 @Override
5777 public String getDeviceId(String callingPackage) {
5778 return getDeviceIdWithFeature(callingPackage, null);
5779 }
5780
Sanket Padawe7310cc72015-01-14 09:53:20 -08005781 /**
5782 * Returns the unique device ID of phone, for example, the IMEI for
5783 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5784 *
5785 * <p>Requires Permission:
5786 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5787 */
5788 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005789 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005790 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005791 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005792 return null;
5793 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005794 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005795 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005796 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005797 return null;
5798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
5802 return phone.getDeviceId();
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
5805 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005806 }
5807
Ping Sunc67b7c22016-03-02 19:16:45 +08005808 /**
5809 * {@hide}
5810 * Returns the IMS Registration Status on a particular subid
5811 *
5812 * @param subId
5813 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005814 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005815 Phone phone = getPhone(subId);
5816 if (phone != null) {
5817 return phone.isImsRegistered();
5818 } else {
5819 return false;
5820 }
5821 }
5822
Santos Cordon7a1885b2015-02-03 11:15:19 -08005823 @Override
5824 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005831 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005832
Tyler Gunnf70ed162019-04-03 15:28:53 -07005833 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005834 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005835 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005837 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005838 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5839 }
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
5842 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
5846 }
5847
5848 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005849 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Phone phone = getPhone(subscriptionId);
5853 if (phone == null) {
5854 return null;
5855 }
5856 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005862 /**
5863 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005864 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005865 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 final long identity = Binder.clearCallingIdentity();
5867 try {
5868 Phone phone = getPhone(subId);
5869 if (phone != null) {
5870 return phone.isWifiCallingEnabled();
5871 } else {
5872 return false;
5873 }
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005876 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005877 }
5878
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005879 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005880 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005881 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005882 public boolean isVideoTelephonyAvailable(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.isVideoEnabled();
5888 } else {
5889 return false;
5890 }
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005893 }
5894 }
5895
5896 /**
5897 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5898 * defined in {@link ImsRegistrationImplBase}.
5899 */
5900 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 Phone phone = getPhone(subId);
5904 if (phone != null) {
5905 return phone.getImsRegistrationTech();
5906 } else {
5907 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5908 }
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005911 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005912 }
5913
Stuart Scott8eef64f2015-04-08 15:13:54 -07005914 @Override
5915 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005916 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005917 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5918 return;
5919 }
5920
Svet Ganovcc087f82015-05-12 20:35:54 -07005921 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005922
Svet Ganovcc087f82015-05-12 20:35:54 -07005923 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005924 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5925 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005926 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005927 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005928 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5930 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005931 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005932 // There has been issues when Sms raw table somehow stores orphan
5933 // fragments. They lead to garbled message when new fragments come
5934 // in and combined with those stale ones. In case this happens again,
5935 // user can reset all network settings which will clean up this table.
5936 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005937 // Clean up IMS settings as well here.
5938 int slotId = getSlotIndex(subId);
5939 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5940 ImsManager.getInstance(mApp, slotId).factoryReset();
5941 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005942
5943 // Erase modem config if erase modem on network setting is enabled.
5944 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5945 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5946 if (configValue != null && Boolean.parseBoolean(configValue)) {
5947 sendEraseModemConfig(getDefaultPhone());
5948 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005949 } finally {
5950 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005951 }
5952 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005953
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005954 private void cleanUpSmsRawTable(Context context) {
5955 ContentResolver resolver = context.getContentResolver();
5956 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5957 resolver.delete(uri, null, null);
5958 }
5959
Narayan Kamath1c496c22015-04-16 14:40:19 +01005960 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005961 public String getSimLocaleForSubscriber(int subId) {
5962 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5963 final Phone phone = getPhone(subId);
5964 if (phone == null) {
5965 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005966 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 final long identity = Binder.clearCallingIdentity();
5969 try {
chen xu5d3637b2019-01-21 23:31:38 -08005970 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005971 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005972 if (info == null) {
5973 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5974 return null;
5975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 // Try and fetch the locale from the carrier properties or from the SIM language
5977 // preferences (EF-PL and EF-LI)...
5978 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005980 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5981 if (localeFromDefaultSim != null) {
5982 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5983 if (DBG) log("Using locale from subId: " + subId + " locale: "
5984 + localeFromDefaultSim);
5985 return localeFromDefaultSim.toLanguageTag();
5986 } else {
5987 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 }
5989 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 // The SIM language preferences only store a language (e.g. fr = French), not an
5992 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5993 // the SIM and carrier preferences does not include a country we add the country
5994 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08005995 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005997 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 return mccLocale.toLanguageTag();
5999 }
6000
6001 if (DBG) log("No locale found - returning null");
6002 return null;
6003 } finally {
6004 Binder.restoreCallingIdentity(identity);
6005 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006006 }
6007
6008 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006009 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6010 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006011 }
6012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 /**
6014 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6015 */
6016 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006017 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6018 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006019 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006020
Chenjie Yu1ba97252018-01-11 18:16:20 -08006021 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006022 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006023
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006024 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006025 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6026 * representing the state of the modem.
6027 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006028 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6029 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006030 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006031 */
6032 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006033 public void requestModemActivityInfo(ResultReceiver result) {
6034 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036
6037 final long identity = Binder.clearCallingIdentity();
6038 try {
6039 ModemActivityInfo ret = null;
6040 synchronized (mLastModemActivityInfo) {
6041 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6042 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006043 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006044 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006046 int[] txTimeMs = info.getTransmitTimeMillis();
6047 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006049 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 }
6051 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006052 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6053 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 mLastModemActivityInfo.setIdleTimeMillis(
6055 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006056 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6057 mLastModemActivityInfo.setReceiveTimeMillis(
6058 info.getReceiveTimeMillis() + mLastModemActivityInfo
6059 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006060 }
Chen Xud78231e2019-09-10 18:49:52 -07006061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6063 mLastModemActivityInfo.getSleepTimeMillis(),
6064 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006065 mLastModemActivityInfo.getTransmitTimeMillis(),
6066 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 Bundle bundle = new Bundle();
6069 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6070 result.send(0, bundle);
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006073 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006074 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006075
Siddharth Rayb8114062018-06-17 15:02:38 -07006076 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6077 // less than total activity duration.
6078 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6079 if (info == null) {
6080 return false;
6081 }
6082 int activityDurationMs =
6083 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6084 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006085 int[] txTimeMs = info.getTransmitTimeMillis();
6086 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6087 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006088 }
6089 return (info.isValid()
6090 && (info.getSleepTimeMillis() <= activityDurationMs)
6091 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006092 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006093 && (totalTxTimeMs <= activityDurationMs));
6094 }
6095
Jack Yu85bd38a2015-11-09 11:34:32 -08006096 /**
6097 * {@hide}
6098 * Returns the service state information on specified subscription.
6099 */
6100 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006101 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6102 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006104 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006105 return null;
6106 }
6107
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6109 LocationAccessPolicy.checkLocationPermission(mApp,
6110 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6111 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006112 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006113 .setCallingPid(Binder.getCallingPid())
6114 .setCallingUid(Binder.getCallingUid())
6115 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006116 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006117 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6118 .build());
6119
6120 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6121 LocationAccessPolicy.checkLocationPermission(mApp,
6122 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6123 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006124 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 .setCallingPid(Binder.getCallingPid())
6126 .setCallingUid(Binder.getCallingUid())
6127 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006128 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006129 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6130 .build());
6131 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6132 boolean hasFinePermission =
6133 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6134 boolean hasCoarsePermission =
6135 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 final Phone phone = getPhone(subId);
6140 if (phone == null) {
6141 return null;
6142 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006143
Hall Liuf19c44f2018-11-27 14:38:17 -08006144 ServiceState ss = phone.getServiceState();
6145
6146 // Scrub out the location info in ServiceState depending on what level of access
6147 // the caller has.
6148 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006149 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6150 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 } finally {
6152 Binder.restoreCallingIdentity(identity);
6153 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006154 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006155
6156 /**
6157 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6158 *
6159 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6160 * voicemail ringtone.
6161 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6162 * PhoneAccount.
6163 */
6164 @Override
6165 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 final long identity = Binder.clearCallingIdentity();
6167 try {
6168 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6169 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006170 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
6176 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006177 }
6178
6179 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006180 * Sets the per-account voicemail ringtone.
6181 *
6182 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6183 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6184 *
6185 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6186 * voicemail ringtone.
6187 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6188 * PhoneAccount.
6189 */
6190 @Override
6191 public void setVoicemailRingtoneUri(String callingPackage,
6192 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006193 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006194 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006195 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6196 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6198 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6199 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201
6202 final long identity = Binder.clearCallingIdentity();
6203 try {
6204 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6205 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006206 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 }
6208 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006211 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006212 }
6213
6214 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006215 * Returns whether vibration is set for voicemail notification in Phone settings.
6216 *
6217 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6218 * voicemail vibration setting.
6219 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6220 */
6221 @Override
6222 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6226 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006227 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006234 }
6235
Youhan Wange64578a2016-05-02 15:32:42 -07006236 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006237 * Sets the per-account voicemail vibration.
6238 *
6239 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6240 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6241 *
6242 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6243 * voicemail vibration setting.
6244 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6245 * specific PhoneAccount.
6246 */
6247 @Override
6248 public void setVoicemailVibrationEnabled(String callingPackage,
6249 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006250 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006251 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006252 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6253 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6255 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6256 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006257 }
6258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6262 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006263 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 }
6265 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6266 } finally {
6267 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006268 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006269 }
6270
6271 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006272 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6273 *
6274 * @throws SecurityException if the caller does not have the required permission
6275 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006276 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006278 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006279 }
6280
6281 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006282 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6283 * permission.
6284 *
6285 * @throws SecurityException if the caller does not have the required permission
6286 */
6287 private void enforceSendSmsPermission() {
6288 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6289 }
6290
6291 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006292 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006293 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006294 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006295 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006296 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 final long identity = Binder.clearCallingIdentity();
6298 try {
6299 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 if (componentName == null) {
6302 throw new SecurityException(
6303 "Caller not current active visual voicemail package[null]");
6304 }
6305 String vvmPackage = componentName.getPackageName();
6306 if (!callingPackage.equals(vvmPackage)) {
6307 throw new SecurityException("Caller not current active visual voicemail package["
6308 + vvmPackage + "]");
6309 }
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006312 }
6313 }
6314
6315 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006316 * Return the application ID for the app type.
6317 *
6318 * @param subId the subscription ID that this request applies to.
6319 * @param appType the uicc app type.
6320 * @return Application ID for specificied app type, or null if no uicc.
6321 */
6322 @Override
6323 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006324 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006325 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326
6327 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006328 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 if (phone == null) {
6330 return null;
6331 }
6332 String aid = null;
6333 try {
6334 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6335 .getApplicationByType(appType).getAid();
6336 } catch (Exception e) {
6337 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6338 }
6339 return aid;
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006342 }
Youhan Wange64578a2016-05-02 15:32:42 -07006343 }
6344
Youhan Wang4001d252016-05-11 10:29:41 -07006345 /**
6346 * Return the Electronic Serial Number.
6347 *
6348 * @param subId the subscription ID that this request applies to.
6349 * @return ESN or null if error.
6350 */
6351 @Override
6352 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006353 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006354 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355
6356 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006357 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 if (phone == null) {
6359 return null;
6360 }
6361 String esn = null;
6362 try {
6363 esn = phone.getEsn();
6364 } catch (Exception e) {
6365 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6366 }
6367 return esn;
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006370 }
Youhan Wang4001d252016-05-11 10:29:41 -07006371 }
6372
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006373 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006374 * Return the Preferred Roaming List Version.
6375 *
6376 * @param subId the subscription ID that this request applies to.
6377 * @return PRLVersion or null if error.
6378 */
6379 @Override
6380 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006381 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006382 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
6384 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006385 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 if (phone == null) {
6387 return null;
6388 }
6389 String cdmaPrlVersion = null;
6390 try {
6391 cdmaPrlVersion = phone.getCdmaPrlVersion();
6392 } catch (Exception e) {
6393 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6394 }
6395 return cdmaPrlVersion;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006398 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006399 }
6400
6401 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006402 * Get snapshot of Telephony histograms
6403 * @return List of Telephony histograms
6404 * @hide
6405 */
6406 @Override
6407 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6409 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 return RIL.getTelephonyRILTimingHistograms();
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006417 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006418
6419 /**
6420 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006421 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6422 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006423 * Require system privileges. In the future we may add this to carrier APIs.
6424 *
Michele Berionne482f8202018-11-27 18:57:59 -08006425 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006426 */
6427 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006428 @TelephonyManager.SetCarrierRestrictionResult
6429 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006430 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006431 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006432
Michele Berionne482f8202018-11-27 18:57:59 -08006433 if (carrierRestrictionRules == null) {
6434 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006435 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 final long identity = Binder.clearCallingIdentity();
6438 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006439 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006440 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 } finally {
6442 Binder.restoreCallingIdentity(identity);
6443 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006444 }
6445
6446 /**
6447 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006448 * Get the allowed carrier list and the excluded carrier list, including the priority between
6449 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006450 * Require system privileges. In the future we may add this to carrier APIs.
6451 *
Michele Berionne482f8202018-11-27 18:57:59 -08006452 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006453 */
6454 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006455 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006456 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006457 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458
6459 final long identity = Binder.clearCallingIdentity();
6460 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006461 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6462 if (response instanceof CarrierRestrictionRules) {
6463 return (CarrierRestrictionRules) response;
6464 }
6465 // Response is an Exception of some kind,
6466 // which is signalled to the user as a NULL retval
6467 return null;
6468 } catch (Exception e) {
6469 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6470 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006474 }
6475
fionaxu59545b42016-05-25 15:53:37 -07006476 /**
6477 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6478 * @param subId the subscription ID that this action applies to.
6479 * @param enabled control enable or disable metered apns.
6480 * {@hide}
6481 */
6482 @Override
6483 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6484 enforceModifyPermission();
6485 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486
6487 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006488 if (phone == null) {
6489 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6490 return;
6491 }
6492 try {
6493 phone.carrierActionSetMeteredApnsEnabled(enabled);
6494 } catch (Exception e) {
6495 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 } finally {
6497 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006498 }
6499 }
6500
6501 /**
6502 * Action set from carrier signalling broadcast receivers to enable/disable radio
6503 * @param subId the subscription ID that this action applies to.
6504 * @param enabled control enable or disable radio.
6505 * {@hide}
6506 */
6507 @Override
6508 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6509 enforceModifyPermission();
6510 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511
6512 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006513 if (phone == null) {
6514 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6515 return;
6516 }
6517 try {
6518 phone.carrierActionSetRadioEnabled(enabled);
6519 } catch (Exception e) {
6520 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521 } finally {
6522 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006523 }
6524 }
6525
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006526 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006527 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6528 * network status based on which carrier apps could apply actions accordingly,
6529 * enable/disable default url handler for example.
6530 *
6531 * @param subId the subscription ID that this action applies to.
6532 * @param report control start/stop reporting the default network status.
6533 * {@hide}
6534 */
6535 @Override
6536 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6537 enforceModifyPermission();
6538 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539
6540 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006541 if (phone == null) {
6542 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6543 return;
6544 }
6545 try {
6546 phone.carrierActionReportDefaultNetworkStatus(report);
6547 } catch (Exception e) {
6548 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006551 }
6552 }
6553
6554 /**
fionaxud9622282017-07-17 17:51:30 -07006555 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6556 * @param subId the subscription ID that this action applies to.
6557 * {@hide}
6558 */
6559 @Override
6560 public void carrierActionResetAll(int subId) {
6561 enforceModifyPermission();
6562 final Phone phone = getPhone(subId);
6563 if (phone == null) {
6564 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6565 return;
6566 }
6567 try {
6568 phone.carrierActionResetAll();
6569 } catch (Exception e) {
6570 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6571 }
6572 }
6573
6574 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006575 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6576 * bug report is being generated.
6577 */
6578 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006579 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6581 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006582 writer.println("Permission Denial: can't dump Phone from pid="
6583 + Binder.getCallingPid()
6584 + ", uid=" + Binder.getCallingUid()
6585 + "without permission "
6586 + android.Manifest.permission.DUMP);
6587 return;
6588 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006589 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006590 }
Jack Yueb89b242016-06-22 13:27:47 -07006591
Brad Ebingerdac2f002018-04-03 15:17:52 -07006592 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006593 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6594 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6595 @NonNull String[] args) {
6596 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6597 this, in.getFileDescriptor(), out.getFileDescriptor(),
6598 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006599 }
6600
Jack Yueb89b242016-06-22 13:27:47 -07006601 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006602 * Get aggregated video call data usage since boot.
6603 *
6604 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6605 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006606 * {@hide}
6607 */
6608 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006609 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006610 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6611 null);
6612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 // NetworkStatsService keeps tracking the active network interface and identity. It
6616 // records the delta with the corresponding network identity.
6617 // We just return the total video call data usage snapshot since boot.
6618 Phone phone = getPhone(subId);
6619 if (phone != null) {
6620 return phone.getVtDataUsage(perUidStats);
6621 }
6622 return null;
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006625 }
Jack Yueb89b242016-06-22 13:27:47 -07006626 }
Jack Yu75ab2952016-07-08 14:29:33 -07006627
6628 /**
6629 * Policy control of data connection. Usually used when data limit is passed.
6630 * @param enabled True if enabling the data, otherwise disabling.
6631 * @param subId Subscription index
6632 * {@hide}
6633 */
6634 @Override
6635 public void setPolicyDataEnabled(boolean enabled, int subId) {
6636 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637
6638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 Phone phone = getPhone(subId);
6641 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006642 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 }
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006646 }
6647 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006648
6649 /**
6650 * Get Client request stats
6651 * @return List of Client Request Stats
6652 * @hide
6653 */
6654 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006655 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6656 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006658 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006659 return null;
6660 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006661 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 if (phone != null) {
6666 return phone.getClientRequestStats();
6667 }
6668
6669 return null;
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006673 }
6674
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006675 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006676 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006677 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006678 }
Jack Yueb4124c2017-02-16 15:32:43 -08006679
6680 /**
Grace Chen70990072017-03-24 17:21:30 -07006681 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006682 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006683 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006684 * @param state State of SIM (power down, power up, pass through)
6685 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6686 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6687 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006688 *
6689 **/
6690 @Override
Grace Chen70990072017-03-24 17:21:30 -07006691 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006692 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006693 Phone phone = PhoneFactory.getPhone(slotIndex);
6694
vagdeviaf9a5b92018-08-15 16:01:53 -07006695 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006700 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 }
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006704 }
6705 }
Shuo Qiandd210312017-04-12 22:11:33 +00006706
Tyler Gunn65d45c22017-06-05 11:22:26 -07006707 private boolean isUssdApiAllowed(int subId) {
6708 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006709 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006710 if (configManager == null) {
6711 return false;
6712 }
6713 PersistableBundle pb = configManager.getConfigForSubId(subId);
6714 if (pb == null) {
6715 return false;
6716 }
6717 return pb.getBoolean(
6718 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6719 }
6720
Shuo Qiandd210312017-04-12 22:11:33 +00006721 /**
6722 * Check if phone is in emergency callback mode
6723 * @return true if phone is in emergency callback mode
6724 * @param subId sub id
6725 */
goneil9c5f4872017-12-05 14:07:56 -08006726 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006727 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006728 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006729 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 if (phone != null) {
6734 return phone.isInEcm();
6735 } else {
6736 return false;
6737 }
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006740 }
6741 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006742
6743 /**
6744 * Get the current signal strength information for the given subscription.
6745 * Because this information is not updated when the device is in a low power state
6746 * it should not be relied-upon to be current.
6747 * @param subId Subscription index
6748 * @return the most recent cached signal strength info from the modem
6749 */
6750 @Override
6751 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 Phone p = getPhone(subId);
6755 if (p == null) {
6756 return null;
6757 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 return p.getSignalStrength();
6760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006763 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006764
Pengquan Meng77b7f132018-08-22 14:49:57 -07006765 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006766 * Get the current modem radio state for the given slot.
6767 * @param slotIndex slot index.
6768 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006769 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006770 * @return the current radio power state from the modem
6771 */
6772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006773 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006774 Phone phone = PhoneFactory.getPhone(slotIndex);
6775 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6777 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006778 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6779 }
6780
6781 final long identity = Binder.clearCallingIdentity();
6782 try {
6783 return phone.getRadioPowerState();
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
6787 }
6788 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6789 }
6790
6791 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006792 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6793 *
6794 * <p>Requires one of the following permissions:
6795 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6796 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6797 * privileges.
6798 *
6799 * @param subId subscription id
6800 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6801 * {@code false}.
6802 */
6803 @Override
6804 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006805 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6806 null /* message */);
6807
Pengquan Menga1bb6272018-09-06 09:59:22 -07006808 boolean isEnabled = false;
6809 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006810 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006811 Phone phone = getPhone(subId);
6812 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006813 } catch (Exception e) {
6814 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6815 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006816 } finally {
6817 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006818 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006819 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006820 }
6821
6822
6823 /**
6824 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6825 *
6826 * <p> Requires permission:
6827 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6828 * privileges.
6829 *
6830 * @param subId subscription id
6831 * @param isEnabled {@code true} means enable, {@code false} means disable.
6832 */
6833 @Override
6834 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6836 mApp, subId, "setDataRoamingEnabled");
6837
Pengquan Menga1bb6272018-09-06 09:59:22 -07006838 final long identity = Binder.clearCallingIdentity();
6839 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006840 Phone phone = getPhone(subId);
6841 if (phone != null) {
6842 phone.setDataRoamingEnabled(isEnabled);
6843 }
6844 } finally {
6845 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006846 }
6847 }
6848
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006849 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006850 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006851 TelephonyPermissions
6852 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006853 mApp, subId, "isManualNetworkSelectionAllowed");
6854
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006855 boolean isAllowed = true;
6856 final long identity = Binder.clearCallingIdentity();
6857 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006858 Phone phone = getPhone(subId);
6859 if (phone != null) {
6860 isAllowed = phone.isCspPlmnEnabled();
6861 }
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
6865 return isAllowed;
6866 }
6867
6868 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006869 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006870 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006871 try {
6872 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006873 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006874 } catch (SecurityException e) {
6875 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6876 // has carrier privileges on an active UICC
6877 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6878 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006879 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006880 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006881 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006885 UiccController uiccController = UiccController.getInstance();
6886 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006887 if (hasReadPermission) {
6888 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006889 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006890
6891 // Remove private info if the caller doesn't have access
6892 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6893 for (UiccCardInfo cardInfo : cardInfos) {
6894 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6895 // is available
6896 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6897 if (card == null || card.getUiccProfile() == null) {
6898 // assume no access if the card or profile is unavailable
6899 filteredInfos.add(cardInfo.getUnprivileged());
6900 continue;
6901 }
6902 UiccProfile profile = card.getUiccProfile();
6903 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6904 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6905 filteredInfos.add(cardInfo);
6906 } else {
6907 filteredInfos.add(cardInfo.getUnprivileged());
6908 }
6909 }
6910 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006911 } finally {
6912 Binder.restoreCallingIdentity(identity);
6913 }
6914 }
6915
6916 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006917 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006918 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6923 if (slots == null) {
6924 Rlog.i(LOG_TAG, "slots is null.");
6925 return null;
6926 }
6927
6928 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6929 for (int i = 0; i < slots.length; i++) {
6930 UiccSlot slot = slots[i];
6931 if (slot == null) {
6932 continue;
6933 }
6934
Jordan Liu7be7e652019-05-06 18:55:02 +00006935 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 UiccCard card = slot.getUiccCard();
6937 if (card != null) {
6938 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006939 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006940 cardId = slot.getEid();
6941 if (TextUtils.isEmpty(cardId)) {
6942 cardId = slot.getIccId();
6943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 }
6945
Jordan Liu857451f2019-05-09 16:35:35 -07006946 if (cardId != null) {
6947 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6948 // if cardId is an EID, it's all digits so this is fine
6949 cardId = IccUtils.stripTrailingFs(cardId);
6950 }
6951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 int cardState = 0;
6953 switch (slot.getCardState()) {
6954 case CARDSTATE_ABSENT:
6955 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6956 break;
6957 case CARDSTATE_PRESENT:
6958 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6959 break;
6960 case CARDSTATE_ERROR:
6961 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6962 break;
6963 case CARDSTATE_RESTRICTED:
6964 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6965 break;
6966 default:
6967 break;
6968
6969 }
6970
6971 infos[i] = new UiccSlotInfo(
6972 slot.isActive(),
6973 slot.isEuicc(),
6974 cardId,
6975 cardState,
6976 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006977 slot.isExtendedApduSupported(),
6978 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 }
6980 return infos;
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006984 }
6985
6986 @Override
6987 public boolean switchSlots(int[] physicalSlots) {
6988 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989
6990 final long identity = Binder.clearCallingIdentity();
6991 try {
6992 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6993 } finally {
6994 Binder.restoreCallingIdentity(identity);
6995 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006996 }
Jack Yu4c988042018-02-27 15:30:01 -08006997
6998 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006999 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007000 final long identity = Binder.clearCallingIdentity();
7001 try {
7002 return UiccController.getInstance().getCardIdForDefaultEuicc();
7003 } finally {
7004 Binder.restoreCallingIdentity(identity);
7005 }
7006 }
7007
7008 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007009 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7010 enforceModifyPermission();
7011 final Phone phone = getPhone(subId);
7012 if (phone == null) {
7013 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7014 return;
7015 }
7016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 phone.setRadioIndicationUpdateMode(filters, mode);
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
Jack Yu4c988042018-02-27 15:30:01 -08007023 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007024
7025 /**
goneil47ffb6e2018-04-06 15:40:58 -07007026 * A test API to reload the UICC profile.
7027 *
7028 * <p>Requires that the calling app has permission
7029 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7030 * @hide
7031 */
7032 @Override
7033 public void refreshUiccProfile(int subId) {
7034 enforceModifyPermission();
7035
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 Phone phone = getPhone(subId);
7039 if (phone == null) {
7040 return;
7041 }
7042 UiccCard uiccCard = phone.getUiccCard();
7043 if (uiccCard == null) {
7044 return;
7045 }
7046 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7047 if (uiccProfile == null) {
7048 return;
7049 }
7050 uiccProfile.refresh();
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
7054 }
7055
7056 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007057 * Returns false if the mobile data is disabled by default, otherwise return true.
7058 */
7059 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007060 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007061 }
7062
7063 /**
7064 * Returns true if the data roaming is enabled by default, i.e the system property
7065 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7066 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7067 */
7068 private boolean getDefaultDataRoamingEnabled(int subId) {
7069 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007070 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007071 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007072 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7073 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7074 return isDataRoamingEnabled;
7075 }
7076
7077 /**
7078 * Returns the default network type for the given {@code subId}, if the default network type is
7079 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7080 */
7081 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007082 List<Integer> list = TelephonyProperties.default_network();
7083 int phoneId = mSubscriptionController.getPhoneId(subId);
7084 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7085 return list.get(phoneId);
7086 }
7087 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007088 }
fionaxua13278b2018-03-21 00:08:13 -07007089
7090 @Override
7091 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007092 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094
7095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 final Phone phone = getPhone(subId);
7098 if (phone == null) {
7099 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7100 return;
7101 }
chen xueaba88a2019-03-15 13:15:10 -07007102 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7103 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 } finally {
7105 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007106 }
fionaxua13278b2018-03-21 00:08:13 -07007107 }
7108
7109 @Override
7110 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007111 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112
7113 final long identity = Binder.clearCallingIdentity();
7114 try {
7115 final Phone phone = getPhone(subId);
7116 if (phone == null) {
7117 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7118 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7119 }
7120 return phone.getCarrierIdListVersion();
7121 } finally {
7122 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007123 }
fionaxua13278b2018-03-21 00:08:13 -07007124 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007125
7126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007127 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7128 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007130 mApp, subId, callingPackage, callingFeatureId,
7131 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007132 return -1;
7133 }
7134
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
7141 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007142
7143 @Override
7144 public int getCdmaRoamingMode(int subId) {
7145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7146 mApp, subId, "getCdmaRoamingMode");
7147
7148 final long identity = Binder.clearCallingIdentity();
7149 try {
7150 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
7154 }
7155
7156 @Override
7157 public boolean setCdmaRoamingMode(int subId, int mode) {
7158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7159 mApp, subId, "setCdmaRoamingMode");
7160
7161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
7167 }
7168
7169 @Override
7170 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7172 mApp, subId, "setCdmaSubscriptionMode");
7173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007181
sqianc5eccab2018-10-19 18:46:41 -07007182 @Override
sqian8c685422019-02-22 15:55:18 -08007183 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007184 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7187 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007188 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7189 }
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
sqian854d44b2018-12-12 16:48:18 -08007192 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7193 for (Phone phone: PhoneFactory.getPhones()) {
7194 if (phone.getEmergencyNumberTracker() != null
7195 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7196 emergencyNumberListInternal.put(
7197 phone.getSubId(),
7198 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7199 }
sqian11b7a0e2018-12-05 18:48:28 -08007200 }
sqian854d44b2018-12-12 16:48:18 -08007201 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
sqianc5eccab2018-10-19 18:46:41 -07007205 }
7206
7207 @Override
sqian8c685422019-02-22 15:55:18 -08007208 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007209 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007210 if (!exactMatch) {
7211 TelephonyPermissions
7212 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007213 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007214 }
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
sqian854d44b2018-12-12 16:48:18 -08007217 for (Phone phone: PhoneFactory.getPhones()) {
7218 if (phone.getEmergencyNumberTracker() != null
7219 && phone.getEmergencyNumberTracker() != null) {
7220 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7221 number, exactMatch)) {
7222 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007223 }
7224 }
sqian11b7a0e2018-12-05 18:48:28 -08007225 }
7226 return false;
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
7230 }
7231
sqianf4ca7ed2019-01-15 18:32:07 -08007232 /**
7233 * Update emergency number list for test mode.
7234 */
7235 @Override
7236 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7238 "updateEmergencyNumberListTestMode");
7239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 for (Phone phone: PhoneFactory.getPhones()) {
7243 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7244 if (tracker != null) {
7245 tracker.executeEmergencyNumberTestModeCommand(action, num);
7246 }
7247 }
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
7251 }
7252
7253 /**
7254 * Get the full emergency number list for test mode.
7255 */
7256 @Override
7257 public List<String> getEmergencyNumberListTestMode() {
7258 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7259 "getEmergencyNumberListTestMode");
7260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 Set<String> emergencyNumbers = new HashSet<>();
7264 for (Phone phone: PhoneFactory.getPhones()) {
7265 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7266 if (tracker != null) {
7267 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7268 emergencyNumbers.add(num.getNumber());
7269 }
7270 }
7271 }
7272 return new ArrayList<>(emergencyNumbers);
7273 } finally {
7274 Binder.restoreCallingIdentity(identity);
7275 }
7276 }
7277
chen xud6b45bd2018-10-30 22:27:10 -07007278 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007279 public int getEmergencyNumberDbVersion(int subId) {
7280 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7281
7282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 final Phone phone = getPhone(subId);
7285 if (phone == null) {
7286 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7287 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7288 }
7289 return phone.getEmergencyNumberDbVersion();
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 @Override
7296 public void notifyOtaEmergencyNumberDbInstalled() {
7297 enforceModifyPermission();
7298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 for (Phone phone: PhoneFactory.getPhones()) {
7302 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7303 if (tracker != null) {
7304 tracker.updateOtaEmergencyNumberDatabase();
7305 }
7306 }
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
7309 }
7310 }
7311
7312 @Override
7313 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7314 enforceActiveEmergencySessionPermission();
7315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 for (Phone phone: PhoneFactory.getPhones()) {
7319 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7320 if (tracker != null) {
7321 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7322 }
7323 }
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
7327 }
7328
7329 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007330 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7331 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7332 Phone phone = getPhone(subId);
7333 if (phone == null) {
7334 return null;
7335 }
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 UiccProfile profile = UiccController.getInstance()
7339 .getUiccProfileForPhone(phone.getPhoneId());
7340 if (profile != null) {
7341 return profile.getCertsFromCarrierPrivilegeAccessRules();
7342 }
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345 }
7346 return null;
7347 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007348
7349 /**
7350 * Enable or disable a modem stack.
7351 */
7352 @Override
7353 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7354 enforceModifyPermission();
7355
7356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 Phone phone = PhoneFactory.getPhone(slotIndex);
7359 if (phone == null) {
7360 return false;
7361 } else {
7362 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7363 }
7364 } finally {
7365 Binder.restoreCallingIdentity(identity);
7366 }
7367 }
Michelecea4cf22018-12-21 15:00:11 -08007368
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007369 /**
7370 * Whether a modem stack is enabled or not.
7371 */
7372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007373 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7374 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007375 Phone phone = PhoneFactory.getPhone(slotIndex);
7376 if (phone == null) return false;
7377
7378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007379 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7380 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007381 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7382 }
7383
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007386 try {
7387 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7388 } catch (NoSuchElementException ex) {
7389 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7390 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
7394 }
7395
Michelecea4cf22018-12-21 15:00:11 -08007396 @Override
Michele0ea7d782019-03-19 14:58:42 -07007397 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007398 enforceModifyPermission();
7399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007403 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007404 .commit();
7405 } finally {
7406 Binder.restoreCallingIdentity(identity);
7407 }
7408 }
7409
7410 @Override
Michele0ea7d782019-03-19 14:58:42 -07007411 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007412 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007414 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7415 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007416 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007417 }
Michelecea4cf22018-12-21 15:00:11 -08007418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
Michele0ea7d782019-03-19 14:58:42 -07007421 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007422 } finally {
7423 Binder.restoreCallingIdentity(identity);
7424 }
7425 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007426
Michele0ea7d782019-03-19 14:58:42 -07007427 @TelephonyManager.IsMultiSimSupportedResult
7428 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007429 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7430 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7431 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007432 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7433 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007434 }
7435 // Check if the hardware supports multisim functionality. If usage of multisim is not
7436 // supported by the modem, indicate that it is restricted.
7437 PhoneCapability staticCapability =
7438 mPhoneConfigurationManager.getStaticPhoneCapability();
7439 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007440 loge("isMultiSimSupportedInternal: no static configuration available");
7441 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007442 }
7443 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007444 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7445 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007446 }
7447 // Check if support of multiple SIMs is restricted by carrier
7448 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007449 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007450 }
7451
Michele0ea7d782019-03-19 14:58:42 -07007452 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007453 }
7454
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007455 /**
7456 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007457 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7458 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7459 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007460 * @param numOfSims number of active sims we want to switch to
7461 */
7462 @Override
7463 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007464 if (numOfSims == 1) {
7465 enforceModifyPermission();
7466 } else {
7467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7468 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7469 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007470 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007471
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007472 try {
Michele30b57b22019-03-01 12:01:14 -08007473 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007474 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007475 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7476 return;
7477 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007478 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
7482 }
7483
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007484 @Override
7485 public boolean isApplicationOnUicc(int subId, int appType) {
7486 enforceReadPrivilegedPermission("isApplicationOnUicc");
7487 Phone phone = getPhone(subId);
7488 if (phone == null) {
7489 return false;
7490 }
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 UiccCard uiccCard = phone.getUiccCard();
7494 if (uiccCard == null) {
7495 return false;
7496 }
7497 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7498 if (uiccProfile == null) {
7499 return false;
7500 }
7501 if (TelephonyManager.APPTYPE_SIM <= appType
7502 && appType <= TelephonyManager.APPTYPE_ISIM) {
7503 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7504 }
7505 return false;
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
7509 }
7510
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007511 /**
chen xub4baa772019-04-03 10:23:41 -07007512 * Get whether making changes to modem configurations will trigger reboot.
7513 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007514 */
7515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7517 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 mApp, subId, callingPackage, callingFeatureId,
7520 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007521 return false;
7522 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
7529 }
7530
Nathan Harold29f5f052019-02-15 13:41:57 -08007531 private void updateModemStateMetrics() {
7532 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7533 // TODO: check the state for each modem if the api is ready.
7534 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7535 }
7536
Pengquan Meng3889a572019-01-23 11:16:29 -08007537 @Override
7538 public int[] getSlotsMapping() {
7539 enforceReadPrivilegedPermission("getSlotsMapping");
7540
7541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7544 // All logical slots should have a mapping to a physical slot.
7545 int[] logicalSlotsMapping = new int[phoneCount];
7546 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7547 for (int i = 0; i < slotInfos.length; i++) {
7548 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7549 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7550 }
7551 }
7552 return logicalSlotsMapping;
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
7556 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007557
7558 /**
7559 * Get the IRadio HAL Version
7560 */
7561 @Override
7562 public int getRadioHalVersion() {
7563 Phone phone = getDefaultPhone();
7564 if (phone == null) return -1;
7565 HalVersion hv = phone.getHalVersion();
7566 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7567 return hv.major * 100 + hv.minor;
7568 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007569
7570 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007571 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7572 * corresponding network requests on a subId.
7573 *
7574 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007575 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007576 * 2) APN is un-metered for this subscription, or
7577 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007578 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007579 *
7580 * @return whether data is allowed for a apn type.
7581 *
7582 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007583 */
7584 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007585 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007586 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7587 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007588
7589 // Now that all security checks passes, perform the operation as ourselves.
7590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 Phone phone = getPhone(subId);
7593 if (phone == null) return false;
7594
Jack Yu41407ee2019-05-13 16:54:09 -07007595 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007596 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7597 } finally {
7598 Binder.restoreCallingIdentity(identity);
7599 }
7600 }
7601
7602 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007603 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007604 enforceReadPrivilegedPermission("isApnMetered");
7605
7606 // Now that all security checks passes, perform the operation as ourselves.
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 Phone phone = getPhone(subId);
7610 if (phone == null) return true; // By default return true.
7611
Jack Yu41407ee2019-05-13 16:54:09 -07007612 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
7616 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007617
7618 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007619 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7620 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7621 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7622 if (iccRecords == null) {
7623 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7624 return false;
7625 }
7626 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7627 }
7628
7629 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007630 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7631 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7632 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7633 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7634 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7635 }
7636 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7637 Intent intent = new Intent();
7638 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7639 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7640 // Bring up choose default SMS subscription dialog right now
7641 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7642 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7643 mApp.startActivity(intent);
7644 }
chen xud5ca2d52019-05-28 15:20:57 -07007645
7646 @Override
7647 public String getMmsUAProfUrl(int subId) {
7648 //TODO investigate if this API should require proper permission check in R b/133791609
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7652 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
7656 }
7657
7658 @Override
7659 public String getMmsUserAgent(int subId) {
7660 //TODO investigate if this API should require proper permission check in R b/133791609
7661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7664 .getString(com.android.internal.R.string.config_mms_user_agent);
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
Jack Yub07d4972019-05-28 16:12:25 -07007669
7670 @Override
7671 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7672 enforceModifyPermission();
7673
7674 // Now that all security checks passes, perform the operation as ourselves.
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 Phone phone = getPhone(subId);
7678 if (phone == null) return false;
7679
7680 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
7683 }
7684 }
7685
7686 @Override
7687 public boolean isDataAllowedInVoiceCall(int subId) {
7688 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7689
7690 // Now that all security checks passes, perform the operation as ourselves.
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 Phone phone = getPhone(subId);
7694 if (phone == null) return false;
7695
7696 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007701
changbettyd5c246e2019-12-24 15:40:37 +08007702 @Override
7703 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7704 enforceModifyPermission();
7705
7706 // Now that all security checks passes, perform the operation as ourselves.
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 Phone phone = getPhone(subId);
7710 if (phone == null) return false;
7711
7712 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
7716 }
7717
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007718 /**
7719 * Updates whether conference event pacakge handling is enabled.
7720 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7721 * otherwise.
7722 */
7723 @Override
7724 public void setCepEnabled(boolean isCepEnabled) {
7725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7726
7727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7730 for (Phone phone : PhoneFactory.getPhones()) {
7731 Phone defaultPhone = phone.getImsPhone();
7732 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7733 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7734 ImsPhoneCallTracker imsPhoneCallTracker =
7735 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7736 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7737 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7738 + imsPhone.getMsisdn());
7739 }
7740 }
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
7744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007745}