blob: d14939bd0b32774bf6f3b43c5a47384ecbedbe6b [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070082import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
94import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger35c841c2018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800124import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800126import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700129import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700132import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800133import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700134import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700135import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700136import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700137import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700138import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700140import com.android.internal.telephony.SmsApplication;
141import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800142import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.TelephonyPermissions;
sqianf4ca7ed2019-01-15 18:32:07 -0800144import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700145import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800146import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800147import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.uicc.IccIoResult;
149import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800150import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700151import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800152import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000155import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700156import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800157import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700158import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800159import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700160import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700161import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700163import java.io.FileDescriptor;
164import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800165import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700168import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800169import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800171import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100172import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import java.util.Map;
sqianf4ca7ed2019-01-15 18:32:07 -0800174import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175
176/**
177 * Implementation of the ITelephony interface.
178 */
Santos Cordon117fee72014-05-16 17:56:12 -0700179public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180 private static final String LOG_TAG = "PhoneInterfaceManager";
181 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
182 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184
185 // Message codes used with mMainThreadHandler
186 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700187 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
188 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189 private static final int CMD_OPEN_CHANNEL = 9;
190 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
191 private static final int CMD_CLOSE_CHANNEL = 11;
192 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800193 private static final int CMD_NV_READ_ITEM = 13;
194 private static final int EVENT_NV_READ_ITEM_DONE = 14;
195 private static final int CMD_NV_WRITE_ITEM = 15;
196 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
197 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
198 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700199 private static final int CMD_RESET_MODEM_CONFIG = 19;
200 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800201 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
202 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
203 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
204 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800205 private static final int CMD_SEND_ENVELOPE = 25;
206 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000207 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
208 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700209 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
210 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
211 private static final int CMD_EXCHANGE_SIM_IO = 31;
212 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800213 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
214 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700215 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
216 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700217 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
218 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700219 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
220 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
221 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700223 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
224 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
225 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
226 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700227 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800228 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
229 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000230 private static final int CMD_SWITCH_SLOTS = 50;
231 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700232 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
233 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
234 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
235 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
236 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
237 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
238 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
239 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700240 private static final int CMD_GET_ALL_CELL_INFO = 60;
241 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
242 private static final int CMD_GET_CELL_LOCATION = 62;
243 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700244 private static final int CMD_MODEM_REBOOT = 64;
245 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700246 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
247 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800248 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
249 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800251 // Parameters of select command.
252 private static final int SELECT_COMMAND = 0xA4;
253 private static final int SELECT_P1 = 0x04;
254 private static final int SELECT_P2 = 0;
255 private static final int SELECT_P3 = 0x10;
256
Pengquan Meng85728fb2018-03-12 16:31:21 -0700257 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
258 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
259 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
260
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 /** The singleton instance. */
262 private static PhoneInterfaceManager sInstance;
263
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800265 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700266 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800267 private AppOpsManager mAppOps;
268 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800269 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800270 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700271 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272
Derek Tan97ebb422014-09-05 16:55:38 -0700273 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
274 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800276 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700277
Michelecea4cf22018-12-21 15:00:11 -0800278 // String to store multi SIM allowed
279 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
280
Derek Tan740e1672017-06-27 14:56:27 -0700281 // The AID of ISD-R.
282 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
283
yinxub1bed742017-04-17 11:45:04 -0700284 private NetworkScanRequestTracker mNetworkScanRequestTracker;
285
David Kelly5e06a7f2018-03-12 14:10:59 +0000286 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
287 private static final int MANUFACTURER_CODE_LENGTH = 8;
288
Derek Tan89e89d42014-07-08 17:00:10 -0700289 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700290 * A request object to use for transmitting data to an ICC.
291 */
292 private static final class IccAPDUArgument {
293 public int channel, cla, command, p1, p2, p3;
294 public String data;
295
296 public IccAPDUArgument(int channel, int cla, int command,
297 int p1, int p2, int p3, String data) {
298 this.channel = channel;
299 this.cla = cla;
300 this.command = command;
301 this.p1 = p1;
302 this.p2 = p2;
303 this.p3 = p3;
304 this.data = data;
305 }
306 }
307
308 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700309 * A request object to use for transmitting data to an ICC.
310 */
311 private static final class ManualNetworkSelectionArgument {
312 public OperatorInfo operatorInfo;
313 public boolean persistSelection;
314
315 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
316 this.operatorInfo = operatorInfo;
317 this.persistSelection = persistSelection;
318 }
319 }
320
321 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
323 * request after sending. The main thread will notify the request when it is complete.
324 */
325 private static final class MainThreadRequest {
326 /** The argument to use for the request */
327 public Object argument;
328 /** The result of the request that is run on the main thread */
329 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800330 // The subscriber id that this request applies to. Defaults to
331 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
332 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333
Nathan Harold92bed182018-10-12 18:16:49 -0700334 // In cases where subId is unavailable, the caller needs to specify the phone.
335 public Phone phone;
336
vagdeviaf9a5b92018-08-15 16:01:53 -0700337 public WorkSource workSource;
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 public MainThreadRequest(Object argument) {
340 this.argument = argument;
341 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800342
Nathan Harold92bed182018-10-12 18:16:49 -0700343 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
344 this.argument = argument;
345 if (phone != null) {
346 this.phone = phone;
347 }
348 this.workSource = workSource;
349 }
350
vagdeviaf9a5b92018-08-15 16:01:53 -0700351 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800352 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 if (subId != null) {
354 this.subId = subId;
355 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700356 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 }
359
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800360 private static final class IncomingThirdPartyCallArgs {
361 public final ComponentName component;
362 public final String callId;
363 public final String callerDisplayName;
364
365 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
366 String callerDisplayName) {
367 this.component = component;
368 this.callId = callId;
369 this.callerDisplayName = callerDisplayName;
370 }
371 }
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 /**
374 * A handler that processes messages on the main thread in the phone process. Since many
375 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
376 * inbound binder threads to the main thread in the phone process. The Binder thread
377 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
378 * on, which will be notified when the operation completes and will contain the result of the
379 * request.
380 *
381 * <p>If a MainThreadRequest object is provided in the msg.obj field,
382 * note that request.result must be set to something non-null for the calling thread to
383 * unblock.
384 */
385 private final class MainThreadHandler extends Handler {
386 @Override
387 public void handleMessage(Message msg) {
388 MainThreadRequest request;
389 Message onCompleted;
390 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800391 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700392 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800393 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394
395 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700396 case CMD_HANDLE_USSD_REQUEST: {
397 request = (MainThreadRequest) msg.obj;
398 final Phone phone = getPhoneFromRequest(request);
399 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
400 String ussdRequest = ussdObject.first;
401 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700402
Pengquan Menga1bb6272018-09-06 09:59:22 -0700403 if (!isUssdApiAllowed(request.subId)) {
404 // Carrier does not support use of this API, return failure.
405 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
406 UssdResponse response = new UssdResponse(ussdRequest, null);
407 Bundle returnData = new Bundle();
408 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
409 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 request.result = true;
412 notifyRequester(request);
413 return;
414 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700415
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 try {
417 request.result = phone != null
418 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
419 } catch (CallStateException cse) {
420 request.result = false;
421 }
422 // Wake up the requesting thread
423 notifyRequester(request);
424 break;
pkanwar32d516d2016-10-14 19:37:38 -0700425 }
426
Yorke Lee716f67e2015-06-17 15:39:16 -0700427 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700429 final Phone phone = getPhoneFromRequest(request);
430 request.result = phone != null ?
431 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
432 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700434 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700442 if (uiccCard == null) {
443 loge("iccTransmitApduLogicalChannel: No UICC");
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
448 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700449 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 iccArgument.channel, iccArgument.cla, iccArgument.command,
451 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 break;
455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 ar = (AsyncResult) msg.obj;
458 request = (MainThreadRequest) ar.userObj;
459 if (ar.exception == null && ar.result != null) {
460 request.result = ar.result;
461 } else {
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
463 if (ar.result == null) {
464 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800465 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800467 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 } else {
469 loge("iccTransmitApduLogicalChannel: Unknown exception");
470 }
471 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 break;
474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
476 request = (MainThreadRequest) msg.obj;
477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduBasicChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 } else {
484 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
485 request);
486 uiccCard.iccTransmitApduBasicChannel(
487 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
488 iccArgument.p3, iccArgument.data, onCompleted);
489 }
490 break;
491
492 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
493 ar = (AsyncResult) msg.obj;
494 request = (MainThreadRequest) ar.userObj;
495 if (ar.exception == null && ar.result != null) {
496 request.result = ar.result;
497 } else {
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
499 if (ar.result == null) {
500 loge("iccTransmitApduBasicChannel: Empty response");
501 } else if (ar.exception instanceof CommandException) {
502 loge("iccTransmitApduBasicChannel: CommandException: " +
503 ar.exception);
504 } else {
505 loge("iccTransmitApduBasicChannel: Unknown exception");
506 }
507 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 break;
510
511 case CMD_EXCHANGE_SIM_IO:
512 request = (MainThreadRequest) msg.obj;
513 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 if (uiccCard == null) {
516 loge("iccExchangeSimIO: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 } else {
520 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
521 request);
522 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
523 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
524 iccArgument.data, onCompleted);
525 }
526 break;
527
528 case EVENT_EXCHANGE_SIM_IO_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
533 } else {
534 request.result = new IccIoResult(0x6f, 0, (byte[])null);
535 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 break;
538
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 case CMD_SEND_ENVELOPE:
540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800541 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 if (uiccCard == null) {
543 loge("sendEnvelopeWithStatus: No UICC");
544 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 } else {
547 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
548 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
549 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 break;
551
552 case EVENT_SEND_ENVELOPE_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
559 if (ar.result == null) {
560 loge("sendEnvelopeWithStatus: Empty response");
561 } else if (ar.exception instanceof CommandException) {
562 loge("sendEnvelopeWithStatus: CommandException: " +
563 ar.exception);
564 } else {
565 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
566 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800569 break;
570
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 case CMD_OPEN_CHANNEL:
572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 if (uiccCard == null) {
576 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800577 request.result = new IccOpenLogicalChannelResponse(-1,
578 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
581 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
583 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 break;
586
587 case EVENT_OPEN_CHANNEL_DONE:
588 ar = (AsyncResult) msg.obj;
589 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 int[] result = (int[]) ar.result;
593 int channelId = result[0];
594 byte[] selectResponse = null;
595 if (result.length > 1) {
596 selectResponse = new byte[result.length - 1];
597 for (int i = 1; i < result.length; ++i) {
598 selectResponse[i - 1] = (byte) result[i];
599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 if (ar.result == null) {
605 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 if (ar.exception != null) {
608 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
609 }
610
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700612 if (ar.exception instanceof CommandException) {
613 CommandException.Error error =
614 ((CommandException) (ar.exception)).getCommandError();
615 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700617 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(
622 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700624 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 break;
627
628 case CMD_CLOSE_CHANNEL:
629 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800630 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 if (uiccCard == null) {
632 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900633 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
637 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
641 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800642 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
643 break;
644
645 case CMD_NV_READ_ITEM:
646 request = (MainThreadRequest) msg.obj;
647 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800648 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
649 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800650 break;
651
652 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 ar = (AsyncResult) msg.obj;
654 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800655 if (ar.exception == null && ar.result != null) {
656 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800658 request.result = "";
659 if (ar.result == null) {
660 loge("nvReadItem: Empty response");
661 } else if (ar.exception instanceof CommandException) {
662 loge("nvReadItem: CommandException: " +
663 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
667 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
Jake Hambye994d462014-02-03 13:10:13 -0800671 case CMD_NV_WRITE_ITEM:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
674 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800675 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700676 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
679 case EVENT_NV_WRITE_ITEM_DONE:
680 handleNullReturnEvent(msg, "nvWriteItem");
681 break;
682
683 case CMD_NV_WRITE_CDMA_PRL:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800686 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_WRITE_CDMA_PRL_DONE:
690 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
691 break;
692
chen xu6dac5ab2018-10-26 17:39:23 -0700693 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800694 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700695 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
chen xu6dac5ab2018-10-26 17:39:23 -0700699 case EVENT_RESET_MODEM_CONFIG_DONE:
700 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 case CMD_GET_PREFERRED_NETWORK_TYPE:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700706 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 break;
708
709 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
710 ar = (AsyncResult) msg.obj;
711 request = (MainThreadRequest) ar.userObj;
712 if (ar.exception == null && ar.result != null) {
713 request.result = ar.result; // Integer
714 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800715 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 if (ar.result == null) {
717 loge("getPreferredNetworkType: Empty response");
718 } else if (ar.exception instanceof CommandException) {
719 loge("getPreferredNetworkType: CommandException: " +
720 ar.exception);
721 } else {
722 loge("getPreferredNetworkType: Unknown exception");
723 }
724 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 break;
727
728 case CMD_SET_PREFERRED_NETWORK_TYPE:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
731 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700732 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
736 handleNullReturnEvent(msg, "setPreferredNetworkType");
737 break;
738
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000739 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
740 request = (MainThreadRequest)msg.obj;
741 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800742 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000743 break;
744
745 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
746 ar = (AsyncResult)msg.obj;
747 request = (MainThreadRequest)ar.userObj;
748 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 break;
751
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800752 case CMD_SET_VOICEMAIL_NUMBER:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
755 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800756 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
757 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800758 break;
759
760 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
761 handleNullReturnEvent(msg, "setVoicemailNumber");
762 break;
763
Stuart Scott54788802015-03-30 13:18:01 -0700764 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
767 request);
768 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
769 break;
770
771 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
772 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
773 break;
774
Shishir Agrawal302c8692015-06-19 13:49:39 -0700775 case CMD_PERFORM_NETWORK_SCAN:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
778 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
779 break;
780
781 case EVENT_PERFORM_NETWORK_SCAN_DONE:
782 ar = (AsyncResult) msg.obj;
783 request = (MainThreadRequest) ar.userObj;
784 CellNetworkScanResult cellScanResult;
785 if (ar.exception == null && ar.result != null) {
786 cellScanResult = new CellNetworkScanResult(
787 CellNetworkScanResult.STATUS_SUCCESS,
788 (List<OperatorInfo>) ar.result);
789 } else {
790 if (ar.result == null) {
791 loge("getCellNetworkScanResults: Empty response");
792 }
793 if (ar.exception != null) {
794 loge("getCellNetworkScanResults: Exception: " + ar.exception);
795 }
796 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
797 if (ar.exception instanceof CommandException) {
798 CommandException.Error error =
799 ((CommandException) (ar.exception)).getCommandError();
800 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
801 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
802 } else if (error == CommandException.Error.GENERIC_FAILURE) {
803 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
804 }
805 }
806 cellScanResult = new CellNetworkScanResult(errorCode, null);
807 }
808 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700809 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
813 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700814 ManualNetworkSelectionArgument selArg =
815 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700816 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
817 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700818 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
819 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 break;
821
822 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null) {
826 request.result = true;
827 } else {
828 request.result = false;
829 loge("setNetworkSelectionModeManual " + ar.exception);
830 }
831 notifyRequester(request);
832 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700835 case CMD_GET_MODEM_ACTIVITY_INFO:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800838 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 break;
840
841 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
842 ar = (AsyncResult) msg.obj;
843 request = (MainThreadRequest) ar.userObj;
844 if (ar.exception == null && ar.result != null) {
845 request.result = ar.result;
846 } else {
847 if (ar.result == null) {
848 loge("queryModemActivityInfo: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("queryModemActivityInfo: CommandException: " +
851 ar.exception);
852 } else {
853 loge("queryModemActivityInfo: Unknown exception");
854 }
855 }
Amit Mahajand4766222016-01-28 15:28:28 -0800856 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
857 if (request.result == null) {
858 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
859 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 case CMD_SET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800865 CarrierRestrictionRules argument =
866 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700867 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800868 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
871 case EVENT_SET_ALLOWED_CARRIERS_DONE:
872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null && ar.result != null) {
875 request.result = ar.result;
876 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800877 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
878 if (ar.exception instanceof CommandException) {
879 loge("setAllowedCarriers: CommandException: " + ar.exception);
880 CommandException.Error error =
881 ((CommandException) (ar.exception)).getCommandError();
882 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
883 request.result =
884 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
885 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 } else {
887 loge("setAllowedCarriers: Unknown exception");
888 }
889 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700890 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case CMD_GET_ALLOWED_CARRIERS:
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800896 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
899 case EVENT_GET_ALLOWED_CARRIERS_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result;
904 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800905 request.result = new IllegalStateException(
906 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 if (ar.result == null) {
908 loge("getAllowedCarriers: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("getAllowedCarriers: CommandException: " +
911 ar.exception);
912 } else {
913 loge("getAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
Nathan Haroldb3014052017-01-25 15:57:32 -0800919 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 if (ar.exception == null && ar.result != null) {
923 request.result = ar.result;
924 } else {
925 request.result = new IllegalArgumentException(
926 "Failed to retrieve Forbidden Plmns");
927 if (ar.result == null) {
928 loge("getForbiddenPlmns: Empty response");
929 } else {
930 loge("getForbiddenPlmns: Unknown exception");
931 }
932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 break;
935
936 case CMD_GET_FORBIDDEN_PLMNS:
937 request = (MainThreadRequest) msg.obj;
938 uiccCard = getUiccCardFromRequest(request);
939 if (uiccCard == null) {
940 loge("getForbiddenPlmns() UiccCard is null");
941 request.result = new IllegalArgumentException(
942 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945 }
946 Integer appType = (Integer) request.argument;
947 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
948 if (uiccApp == null) {
949 loge("getForbiddenPlmns() no app with specified type -- "
950 + appType);
951 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 break;
954 } else {
955 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
956 + " specified type -- " + appType);
957 }
958 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
959 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
960 onCompleted);
961 break;
962
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000963 case CMD_SWITCH_SLOTS:
964 request = (MainThreadRequest) msg.obj;
965 int[] physicalSlots = (int[]) request.argument;
966 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
967 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
968 break;
969
970 case EVENT_SWITCH_SLOTS_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
975 break;
976 case CMD_GET_NETWORK_SELECTION_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
979 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
980 break;
981
982 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception != null) {
986 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
987 } else {
988 int mode = ((int[]) ar.result)[0];
989 if (mode == 0) {
990 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
991 } else {
992 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
993 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000994 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700995 notifyRequester(request);
996 break;
997 case CMD_GET_CDMA_ROAMING_MODE:
998 request = (MainThreadRequest) msg.obj;
999 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1000 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1001 break;
1002 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception != null) {
1006 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1007 } else {
1008 request.result = ((int[]) ar.result)[0];
1009 }
1010 notifyRequester(request);
1011 break;
1012 case CMD_SET_CDMA_ROAMING_MODE:
1013 request = (MainThreadRequest) msg.obj;
1014 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1015 int mode = (int) request.argument;
1016 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1017 break;
1018 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 request.result = ar.exception == null;
1022 notifyRequester(request);
1023 break;
1024 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1027 int subscriptionMode = (int) request.argument;
1028 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1029 break;
1030 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 request.result = ar.exception == null;
1034 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001035 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001036 case CMD_GET_ALL_CELL_INFO:
1037 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001039 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001041 case EVENT_GET_ALL_CELL_INFO_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001044 // If a timeout occurs, the response will be null
1045 request.result = (ar.exception == null && ar.result != null)
1046 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 synchronized (request) {
1048 request.notifyAll();
1049 }
1050 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001051 case CMD_REQUEST_CELL_INFO_UPDATE:
1052 request = (MainThreadRequest) msg.obj;
1053 request.phone.requestCellInfoUpdate(request.workSource,
1054 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1055 break;
1056 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1060 try {
1061 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001063 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1064 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001067 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 } else {
1069 // use the result as returned
1070 cb.onCellInfo((List<CellInfo>) ar.result);
1071 }
1072 } catch (RemoteException re) {
1073 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1074 }
1075 break;
1076 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001077 request = (MainThreadRequest) msg.obj;
1078 WorkSource ws = (WorkSource) request.argument;
1079 Phone phone = getPhoneFromRequest(request);
1080 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1081 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 if (ar.exception == null) {
1086 request.result = ar.result;
1087 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1090 ? new CdmaCellLocation() : new GsmCellLocation();
1091 }
1092
1093 synchronized (request) {
1094 request.notifyAll();
1095 }
1096 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001097 case CMD_MODEM_REBOOT:
1098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001100 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001101 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001102 case EVENT_CMD_MODEM_REBOOT_DONE:
1103 handleNullReturnEvent(msg, "rebootModem");
1104 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001105 case CMD_REQUEST_ENABLE_MODEM:
1106 request = (MainThreadRequest) msg.obj;
1107 boolean enable = (boolean) request.argument;
1108 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001109 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001110 PhoneConfigurationManager.getInstance()
1111 .enablePhone(request.phone, enable, onCompleted);
1112 break;
1113 case EVENT_ENABLE_MODEM_DONE:
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 request.result = (ar.exception == null);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001117 //update the cache as modem status has changed
1118 mPhoneConfigurationManager.addToPhoneStatusCache(
1119 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -08001120 updateModemStateMetrics();
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001121 notifyRequester(request);
1122 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 default:
1124 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1125 break;
1126 }
1127 }
Jake Hambye994d462014-02-03 13:10:13 -08001128
Pengquan Menga1bb6272018-09-06 09:59:22 -07001129 private void notifyRequester(MainThreadRequest request) {
1130 synchronized (request) {
1131 request.notifyAll();
1132 }
1133 }
1134
Jake Hambye994d462014-02-03 13:10:13 -08001135 private void handleNullReturnEvent(Message msg, String command) {
1136 AsyncResult ar = (AsyncResult) msg.obj;
1137 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1138 if (ar.exception == null) {
1139 request.result = true;
1140 } else {
1141 request.result = false;
1142 if (ar.exception instanceof CommandException) {
1143 loge(command + ": CommandException: " + ar.exception);
1144 } else {
1145 loge(command + ": Unknown exception");
1146 }
1147 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001148 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 }
1151
1152 /**
1153 * Posts the specified command to be executed on the main thread,
1154 * waits for the request to complete, and returns the result.
1155 * @see #sendRequestAsync
1156 */
1157 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001158 return sendRequest(
1159 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001160 }
1161
1162 /**
1163 * Posts the specified command to be executed on the main thread,
1164 * waits for the request to complete, and returns the result.
1165 * @see #sendRequestAsync
1166 */
1167 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1168 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001169 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001170 }
1171
1172 /**
1173 * Posts the specified command to be executed on the main thread,
1174 * waits for the request to complete, and returns the result.
1175 * @see #sendRequestAsync
1176 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001177 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001178 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001179 }
1180
1181 /**
1182 * Posts the specified command to be executed on the main thread,
1183 * waits for the request to complete, and returns the result.
1184 * @see #sendRequestAsync
1185 */
Nathan Harold92bed182018-10-12 18:16:49 -07001186 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1187 return sendRequest(command, argument, subId, null, workSource);
1188 }
1189
1190 /**
1191 * Posts the specified command to be executed on the main thread,
1192 * waits for the request to complete, and returns the result.
1193 * @see #sendRequestAsync
1194 */
1195 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1196 return sendRequest(
1197 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1198 }
1199
1200 /**
1201 * Posts the specified command to be executed on the main thread,
1202 * waits for the request to complete, and returns the result.
1203 * @see #sendRequestAsync
1204 */
1205 private Object sendRequest(
1206 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1208 throw new RuntimeException("This method will deadlock if called from the main thread.");
1209 }
1210
Nathan Harold92bed182018-10-12 18:16:49 -07001211 MainThreadRequest request = null;
1212 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1213 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1214 } else if (phone != null) {
1215 request = new MainThreadRequest(argument, phone, workSource);
1216 } else {
1217 request = new MainThreadRequest(argument, subId, workSource);
1218 }
1219
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 Message msg = mMainThreadHandler.obtainMessage(command, request);
1221 msg.sendToTarget();
1222
1223 // Wait for the request to complete
1224 synchronized (request) {
1225 while (request.result == null) {
1226 try {
1227 request.wait();
1228 } catch (InterruptedException e) {
1229 // Do nothing, go back and wait until the request is complete
1230 }
1231 }
1232 }
1233 return request.result;
1234 }
1235
1236 /**
1237 * Asynchronous ("fire and forget") version of sendRequest():
1238 * Posts the specified command to be executed on the main thread, and
1239 * returns immediately.
1240 * @see #sendRequest
1241 */
1242 private void sendRequestAsync(int command) {
1243 mMainThreadHandler.sendEmptyMessage(command);
1244 }
1245
1246 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001247 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001249 */
1250 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001251 sendRequestAsync(command, argument, null, null);
1252 }
1253
1254 /**
1255 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1256 * @see {@link #sendRequest(int,Object)}
1257 */
1258 private void sendRequestAsync(
1259 int command, Object argument, Phone phone, WorkSource workSource) {
1260 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001261 Message msg = mMainThreadHandler.obtainMessage(command, request);
1262 msg.sendToTarget();
1263 }
1264
1265 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 * Initialize the singleton PhoneInterfaceManager instance.
1267 * This is only done once, at startup, from PhoneApp.onCreate().
1268 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001269 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 synchronized (PhoneInterfaceManager.class) {
1271 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001272 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 } else {
1274 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1275 }
1276 return sInstance;
1277 }
1278 }
1279
1280 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001281 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001284 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1286 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001287 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001288 mTelephonySharedPreferences =
1289 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001290 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001291 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 publish();
1294 }
1295
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001296 private Phone getDefaultPhone() {
1297 Phone thePhone = getPhone(getDefaultSubscription());
1298 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1299 }
1300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 private void publish() {
1302 if (DBG) log("publish: " + this);
1303
1304 ServiceManager.addService("phone", this);
1305 }
1306
Stuart Scott584921c2015-01-15 17:10:34 -08001307 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001308 if (request.phone != null) {
1309 return request.phone;
1310 } else {
1311 return getPhoneFromSubId(request.subId);
1312 }
1313 }
1314
1315 private Phone getPhoneFromSubId(int subId) {
1316 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1317 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001318 }
1319
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001320 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1321 Phone phone = getPhoneFromRequest(request);
1322 return phone == null ? null :
1323 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1324 }
1325
Wink Saville36469e72014-06-11 15:17:00 -07001326 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001327 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001328 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330
1331 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Wink Savilleb564aae2014-10-23 10:18:09 -07001335 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 if (DBG) log("dial: " + number);
1337 // No permission check needed here: This is just a wrapper around the
1338 // ACTION_DIAL intent, which is available to any app since it puts up
1339 // the UI before it does anything.
1340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001341 final long identity = Binder.clearCallingIdentity();
1342 try {
1343 String url = createTelUrl(number);
1344 if (url == null) {
1345 return;
1346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001348 // PENDING: should we just silently fail if phone is offhook or ringing?
1349 PhoneConstants.State state = mCM.getState(subId);
1350 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1351 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1353 mApp.startActivity(intent);
1354 }
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 }
1358 }
1359
1360 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 if (DBG) log("call: " + number);
1366
1367 // This is just a wrapper around the ACTION_CALL intent, but we still
1368 // need to do a permission check since we're calling startActivity()
1369 // from the context of the phone app.
1370 enforceCallPermission();
1371
1372 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1373 != AppOpsManager.MODE_ALLOWED) {
1374 return;
1375 }
1376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001377 final long identity = Binder.clearCallingIdentity();
1378 try {
1379 String url = createTelUrl(number);
1380 if (url == null) {
1381 return;
1382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001384 boolean isValid = false;
1385 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1386 if (slist != null) {
1387 for (SubscriptionInfo subInfoRecord : slist) {
1388 if (subInfoRecord.getSubscriptionId() == subId) {
1389 isValid = true;
1390 break;
1391 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001392 }
Wink Saville08874612014-08-31 19:19:58 -07001393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001394 if (!isValid) {
1395 return;
1396 }
Wink Saville08874612014-08-31 19:19:58 -07001397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001398 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1399 intent.putExtra(SUBSCRIPTION_KEY, subId);
1400 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1401 mApp.startActivity(intent);
1402 } finally {
1403 Binder.restoreCallingIdentity(identity);
1404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 }
1406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001408 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001409 }
1410
Wink Savilleb564aae2014-10-23 10:18:09 -07001411 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001412 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001413 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1414 }
1415
1416 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001417 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001418 }
1419
Wink Savilleb564aae2014-10-23 10:18:09 -07001420 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001421 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001422 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1423 }
1424
1425 /** {@hide} */
1426 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432
1433 final long identity = Binder.clearCallingIdentity();
1434 try {
1435 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1436 checkSimPin.start();
1437 return checkSimPin.unlockSim(null, pin);
1438 } finally {
1439 Binder.restoreCallingIdentity(identity);
1440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 }
1442
Wink Saville9de0f752013-10-22 19:04:03 -07001443 /** {@hide} */
1444 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001445 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001446 }
1447
Wink Savilleb564aae2014-10-23 10:18:09 -07001448 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001450
1451 final long identity = Binder.clearCallingIdentity();
1452 try {
1453 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1454 checkSimPuk.start();
1455 return checkSimPuk.unlockSim(puk, pin);
1456 } finally {
1457 Binder.restoreCallingIdentity(identity);
1458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
1460
1461 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001462 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 * a synchronous one.
1464 */
1465 private static class UnlockSim extends Thread {
1466
1467 private final IccCard mSimCard;
1468
1469 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001470 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1471 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
1473 // For replies from SimCard interface
1474 private Handler mHandler;
1475
1476 // For async handler to identify request type
1477 private static final int SUPPLY_PIN_COMPLETE = 100;
1478
1479 public UnlockSim(IccCard simCard) {
1480 mSimCard = simCard;
1481 }
1482
1483 @Override
1484 public void run() {
1485 Looper.prepare();
1486 synchronized (UnlockSim.this) {
1487 mHandler = new Handler() {
1488 @Override
1489 public void handleMessage(Message msg) {
1490 AsyncResult ar = (AsyncResult) msg.obj;
1491 switch (msg.what) {
1492 case SUPPLY_PIN_COMPLETE:
1493 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1494 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001495 mRetryCount = msg.arg1;
1496 if (ar.exception != null) {
1497 if (ar.exception instanceof CommandException &&
1498 ((CommandException)(ar.exception)).getCommandError()
1499 == CommandException.Error.PASSWORD_INCORRECT) {
1500 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1501 } else {
1502 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1503 }
1504 } else {
1505 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507 mDone = true;
1508 UnlockSim.this.notifyAll();
1509 }
1510 break;
1511 }
1512 }
1513 };
1514 UnlockSim.this.notifyAll();
1515 }
1516 Looper.loop();
1517 }
1518
1519 /*
1520 * Use PIN or PUK to unlock SIM card
1521 *
1522 * If PUK is null, unlock SIM card with PIN
1523 *
1524 * If PUK is not null, unlock SIM card with PUK and set PIN code
1525 */
Wink Saville9de0f752013-10-22 19:04:03 -07001526 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527
1528 while (mHandler == null) {
1529 try {
1530 wait();
1531 } catch (InterruptedException e) {
1532 Thread.currentThread().interrupt();
1533 }
1534 }
1535 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1536
1537 if (puk == null) {
1538 mSimCard.supplyPin(pin, callback);
1539 } else {
1540 mSimCard.supplyPuk(puk, pin, callback);
1541 }
1542
1543 while (!mDone) {
1544 try {
1545 Log.d(LOG_TAG, "wait for done");
1546 wait();
1547 } catch (InterruptedException e) {
1548 // Restore the interrupted status
1549 Thread.currentThread().interrupt();
1550 }
1551 }
1552 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001553 int[] resultArray = new int[2];
1554 resultArray[0] = mResult;
1555 resultArray[1] = mRetryCount;
1556 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
1558 }
1559
1560 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001561 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001562
1563 }
1564
Wink Savilleb564aae2014-10-23 10:18:09 -07001565 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 // No permission check needed here: this call is harmless, and it's
1567 // needed for the ServiceState.requestStateUpdate() call (which is
1568 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.updateServiceLocation();
1574 }
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001580 @Override
1581 public boolean isRadioOn(String callingPackage) {
1582 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001583 }
1584
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001585 @Override
1586 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001588 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001589 return false;
1590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001591
1592 final long identity = Binder.clearCallingIdentity();
1593 try {
1594 return isRadioOnForSubscriber(subId);
1595 } finally {
1596 Binder.restoreCallingIdentity(identity);
1597 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001598 }
1599
1600 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001601 final long identity = Binder.clearCallingIdentity();
1602 try {
1603 final Phone phone = getPhone(subId);
1604 if (phone != null) {
1605 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1606 } else {
1607 return false;
1608 }
1609 } finally {
1610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 }
1613
1614 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001615 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
Wink Saville36469e72014-06-11 15:17:00 -07001617
Wink Savilleb564aae2014-10-23 10:18:09 -07001618 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001620
1621 final long identity = Binder.clearCallingIdentity();
1622 try {
1623 final Phone phone = getPhone(subId);
1624 if (phone != null) {
1625 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1626 }
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Wink Saville36469e72014-06-11 15:17:00 -07001630 }
1631
1632 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001633 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001634 }
1635
Wink Savilleb564aae2014-10-23 10:18:09 -07001636 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001638
1639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 final Phone phone = getPhone(subId);
1642 if (phone == null) {
1643 return false;
1644 }
1645 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1646 toggleRadioOnOffForSubscriber(subId);
1647 }
1648 return true;
1649 } finally {
1650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
Wink Saville36469e72014-06-11 15:17:00 -07001653
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 public boolean needMobileRadioShutdown() {
1655 /*
1656 * If any of the Radios are available, it will need to be
1657 * shutdown. So return true if any Radio is available.
1658 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1662 Phone phone = PhoneFactory.getPhone(i);
1663 if (phone != null && phone.isRadioAvailable()) return true;
1664 }
1665 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1666 return false;
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 }
1671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001672 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001673 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001674 enforceModifyPermission();
1675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1679 logv("Shutting down Phone " + i);
1680 shutdownRadioUsingPhoneId(i);
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001684 }
1685 }
1686
1687 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001688 Phone phone = PhoneFactory.getPhone(phoneId);
1689 if (phone != null && phone.isRadioAvailable()) {
1690 phone.shutdownRadio();
1691 }
1692 }
1693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696
1697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1700 if (defaultPhone != null) {
1701 defaultPhone.setRadioPower(turnOn);
1702 return true;
1703 } else {
1704 loge("There's no default phone.");
1705 return false;
1706 }
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001709 }
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
1719 phone.setRadioPower(turnOn);
1720 return true;
1721 } else {
1722 return false;
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Wink Saville36469e72014-06-11 15:17:00 -07001729 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 public boolean enableDataConnectivity() {
1732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 int subId = mSubscriptionController.getDefaultDataSubId();
1737 final Phone phone = getPhone(subId);
1738 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001739 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001740 return true;
1741 } else {
1742 return false;
1743 }
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
Wink Saville36469e72014-06-11 15:17:00 -07001749 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 public boolean disableDataConnectivity() {
1752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 int subId = mSubscriptionController.getDefaultDataSubId();
1757 final Phone phone = getPhone(subId);
1758 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001759 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760 return true;
1761 } else {
1762 return false;
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001770 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 final Phone phone = getPhone(subId);
1774 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001775 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776 } else {
1777 return false;
1778 }
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
1784 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001785 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001786 }
1787
pkanwarae03a6b2016-11-06 20:37:09 -08001788 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789 enforceCallPermission();
1790
1791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1794 return;
1795 }
1796 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1797 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
1800 }
pkanwar32d516d2016-10-14 19:37:38 -07001801 };
1802
Wink Savilleb564aae2014-10-23 10:18:09 -07001803 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1809 return false;
1810 }
1811 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001818 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001819 }
1820
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001821 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 Phone phone = PhoneFactory.getPhone(slotIndex);
1825 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1826 PhoneConstantConversions.convertCallState(phone.getState());
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
1829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1837 if (phone != null) {
1838 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1839 } else {
1840 return PhoneConstantConversions.convertDataState(
1841 PhoneConstants.DataState.DISCONNECTED);
1842 }
1843 } finally {
1844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 }
1847
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1853 if (phone != null) {
1854 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1855 } else {
1856 return TelephonyManager.DATA_ACTIVITY_NONE;
1857 }
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
1863 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001864 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001865 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001866 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001867
1868 LocationAccessPolicy.LocationPermissionResult locationResult =
1869 LocationAccessPolicy.checkLocationPermission(mApp,
1870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1871 .setCallingPackage(callingPackage)
1872 .setCallingPid(Binder.getCallingPid())
1873 .setCallingUid(Binder.getCallingUid())
1874 .setMethod("getCellLocation")
1875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1876 .build());
1877 switch (locationResult) {
1878 case DENIED_HARD:
1879 throw new SecurityException("Not allowed to access cell location");
1880 case DENIED_SOFT:
1881 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 final long identity = Binder.clearCallingIdentity();
1886 try {
1887 if (DBG_LOC) log("getCellLocation: is active user");
1888 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001889 int subId = mSubscriptionController.getDefaultDataSubId();
1890 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1891 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001892 return data;
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
Svetoslav64fad262015-04-14 14:35:21 -07001896 }
1897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001899 public String getNetworkCountryIsoForPhone(int phoneId) {
1900 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1901 // registered cell info, so return a NULL country instead.
1902 final long identity = Binder.clearCallingIdentity();
1903 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001904 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1905 // Get default phone in this case.
1906 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1907 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001908 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001909 // Todo: fix this when we can get the actual cellular network info when the device
1910 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001911 if (TelephonyManager.NETWORK_TYPE_IWLAN
1912 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1913 return "";
1914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 Phone phone = PhoneFactory.getPhone(phoneId);
1916 if (phone != null) {
1917 ServiceStateTracker sst = phone.getServiceStateTracker();
1918 if (sst != null) {
1919 LocaleTracker lt = sst.getLocaleTracker();
1920 if (lt != null) {
1921 return lt.getCurrentCountry();
1922 }
1923 }
1924 }
1925 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001926 } finally {
1927 Binder.restoreCallingIdentity(identity);
1928 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001929 }
1930
1931 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001933 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001934 }
1935
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001937 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 mApp.enforceCallingOrSelfPermission(
1939 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001940
1941 final long identity = Binder.clearCallingIdentity();
1942 try {
1943 final Phone phone = getPhone(subId);
1944 if (phone != null) {
1945 phone.enableLocationUpdates();
1946 }
1947 } finally {
1948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
1952 @Override
1953 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001954 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001958 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 mApp.enforceCallingOrSelfPermission(
1960 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001961
1962 final long identity = Binder.clearCallingIdentity();
1963 try {
1964 final Phone phone = getPhone(subId);
1965 if (phone != null) {
1966 phone.disableLocationUpdates();
1967 }
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
Nathan Harold31d7ff32018-10-15 20:20:30 -07001973 /**
1974 * Returns the target SDK version number for a given package name.
1975 *
1976 * @return target SDK if the package is found or INT_MAX.
1977 */
1978 private int getTargetSdk(String packageName) {
1979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001980 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1981 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001982 if (ai != null) return ai.targetSdkVersion;
1983 } catch (PackageManager.NameNotFoundException unexpected) {
1984 }
1985 return Integer.MAX_VALUE;
1986 }
1987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 @Override
1989 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001990 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1991 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001992 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1993 throw new SecurityException(
1994 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1995 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001996
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1998 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1999 return null;
2000 }
Svetoslav64fad262015-04-14 14:35:21 -07002001
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002002 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003
Nathan Haroldf180aac2018-06-01 18:43:55 -07002004 List<CellInfo> info = getAllCellInfo(callingPackage);
2005 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006
Nathan Haroldf180aac2018-06-01 18:43:55 -07002007 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2008 for (CellInfo ci : info) {
2009 if (ci instanceof CellInfoGsm) {
2010 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2011 } else if (ci instanceof CellInfoWcdma) {
2012 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002015 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 }
2017
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 private List<CellInfo> getCachedCellInfo() {
2019 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2020 for (Phone phone : PhoneFactory.getPhones()) {
2021 List<CellInfo> info = phone.getAllCellInfo();
2022 if (info != null) cellInfos.addAll(info);
2023 }
2024 return cellInfos;
2025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026
2027 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002028 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002029 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002030 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002031
2032 LocationAccessPolicy.LocationPermissionResult locationResult =
2033 LocationAccessPolicy.checkLocationPermission(mApp,
2034 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2035 .setCallingPackage(callingPackage)
2036 .setCallingPid(Binder.getCallingPid())
2037 .setCallingUid(Binder.getCallingUid())
2038 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002039 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002040 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2041 .build());
2042 switch (locationResult) {
2043 case DENIED_HARD:
2044 throw new SecurityException("Not allowed to access cell info");
2045 case DENIED_SOFT:
2046 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 }
2048
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002049 final int targetSdk = getTargetSdk(callingPackage);
2050 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2051 return getCachedCellInfo();
2052 }
2053
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002054 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2059 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002060 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002061 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 if (info != null) cellInfos.addAll(info);
2063 }
2064 return cellInfos;
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 }
2068 }
2069
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002070 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002071 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2072 requestCellInfoUpdateInternal(
2073 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2074 }
2075
2076 @Override
2077 public void requestCellInfoUpdateWithWorkSource(
2078 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2079 enforceModifyPermission();
2080 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2081 }
2082
2083 private void requestCellInfoUpdateInternal(
2084 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002085 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002086 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002087
2088 LocationAccessPolicy.LocationPermissionResult locationResult =
2089 LocationAccessPolicy.checkLocationPermission(mApp,
2090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2091 .setCallingPackage(callingPackage)
2092 .setCallingPid(Binder.getCallingPid())
2093 .setCallingUid(Binder.getCallingUid())
2094 .setMethod("requestCellInfoUpdate")
2095 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2096 .build());
2097 switch (locationResult) {
2098 case DENIED_HARD:
2099 throw new SecurityException("Not allowed to access cell info");
2100 case DENIED_SOFT:
2101 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002102 }
2103
2104 final Phone phone = getPhone(subId);
2105 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2106
2107 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2108 }
2109
2110 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002112 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002113 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002117 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
Shishir Agrawala9f32182016-04-12 12:00:16 -07002123 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002124 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002125 Phone phone = PhoneFactory.getPhone(slotIndex);
2126 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002127 return null;
2128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002129 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002130 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2131 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002132 return null;
2133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 return phone.getImei();
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
2140 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002141 }
2142
2143 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002144 public String getTypeAllocationCodeForSlot(int slotIndex) {
2145 Phone phone = PhoneFactory.getPhone(slotIndex);
2146 String tac = null;
2147 if (phone != null) {
2148 String imei = phone.getImei();
2149 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2150 }
2151 return tac;
2152 }
2153
2154 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002155 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002156 Phone phone = PhoneFactory.getPhone(slotIndex);
2157 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002158 return null;
2159 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002160
Jeff Davidson913390f2018-02-23 17:11:49 -08002161 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002162 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2163 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002164 return null;
2165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166
2167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 return phone.getMeid();
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
2172 }
Jack Yu2af8d712017-03-15 17:14:14 -07002173 }
2174
2175 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002176 public String getManufacturerCodeForSlot(int slotIndex) {
2177 Phone phone = PhoneFactory.getPhone(slotIndex);
2178 String manufacturerCode = null;
2179 if (phone != null) {
2180 String meid = phone.getMeid();
2181 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2182 }
2183 return manufacturerCode;
2184 }
2185
2186 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002188 Phone phone = PhoneFactory.getPhone(slotIndex);
2189 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 return null;
2191 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002192 int subId = phone.getSubId();
2193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2194 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2195 return null;
2196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 return phone.getDeviceSvn();
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
2203 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002204 }
2205
fionaxu43304da2017-11-27 22:51:16 -08002206 @Override
2207 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 final Phone phone = getPhone(subId);
2211 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
2214 }
fionaxu43304da2017-11-27 22:51:16 -08002215 }
2216
2217 @Override
2218 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 final Phone phone = getPhone(subId);
2222 return phone == null ? null : phone.getCarrierName();
2223 } finally {
2224 Binder.restoreCallingIdentity(identity);
2225 }
fionaxu43304da2017-11-27 22:51:16 -08002226 }
2227
calvinpanffe225e2018-11-01 19:43:06 +08002228 @Override
chen xu0026ca62019-03-06 15:28:50 -08002229 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 final Phone phone = getPhone(subId);
2233 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002234 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002235 } finally {
2236 Binder.restoreCallingIdentity(identity);
2237 }
2238 }
2239
2240 @Override
chen xu0026ca62019-03-06 15:28:50 -08002241 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002245 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002246 } finally {
2247 Binder.restoreCallingIdentity(identity);
2248 }
2249 }
2250
chen xu651eec72018-11-11 19:03:44 -08002251 @Override
chen xu864e11c2018-12-06 22:10:03 -08002252 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2253 if (!isSubscriptionMccMnc) {
2254 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2255 }
chen xu651eec72018-11-11 19:03:44 -08002256 final Phone phone = PhoneFactory.getPhone(slotIndex);
2257 if (phone == null) {
2258 return TelephonyManager.UNKNOWN_CARRIER_ID;
2259 }
2260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
2266 }
2267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 //
2269 // Internal helper methods.
2270 //
2271
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002272 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2274 *
2275 * @throws SecurityException if the caller does not have the required permission
2276 */
2277 private void enforceModifyPermission() {
2278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2279 }
2280
2281 /**
2282 * Make sure the caller has the CALL_PHONE permission.
2283 *
2284 * @throws SecurityException if the caller does not have the required permission
2285 */
2286 private void enforceCallPermission() {
2287 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2288 }
2289
Stuart Scott8eef64f2015-04-08 15:13:54 -07002290 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002291 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002292 "ConnectivityService");
2293 }
2294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 private String createTelUrl(String number) {
2296 if (TextUtils.isEmpty(number)) {
2297 return null;
2298 }
2299
Jake Hambye994d462014-02-03 13:10:13 -08002300 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
Ihab Awadf9e92732013-12-05 18:02:52 -08002303 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2305 }
2306
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002307 private static void logv(String msg) {
2308 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2309 }
2310
Ihab Awadf9e92732013-12-05 18:02:52 -08002311 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2313 }
2314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002317 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002321 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 final Phone phone = PhoneFactory.getPhone(slotIndex);
2325 if (phone == null) {
2326 return PhoneConstants.PHONE_TYPE_NONE;
2327 } else {
2328 return phone.getPhoneType();
2329 }
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
2335 /**
2336 * Returns the CDMA ERI icon index to display
2337 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 @Override
2339 public int getCdmaEriIconIndex(String callingPackage) {
2340 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002341 }
2342
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002344 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002346 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 return -1;
2348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349
2350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 if (phone != null) {
2354 return phone.getCdmaEriIconIndex();
2355 } else {
2356 return -1;
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 }
2362
2363 /**
2364 * Returns the CDMA ERI icon mode,
2365 * 0 - ON
2366 * 1 - FLASHING
2367 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002368 @Override
2369 public int getCdmaEriIconMode(String callingPackage) {
2370 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002371 }
2372
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002374 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002376 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 return -1;
2378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone phone = getPhone(subId);
2383 if (phone != null) {
2384 return phone.getCdmaEriIconMode();
2385 } else {
2386 return -1;
2387 }
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
2392
2393 /**
2394 * Returns the CDMA ERI text,
2395 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002396 @Override
2397 public String getCdmaEriText(String callingPackage) {
2398 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002399 }
2400
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002404 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 return null;
2406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 if (phone != null) {
2412 return phone.getCdmaEriText();
2413 } else {
2414 return null;
2415 }
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
2421 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002422 * Returns the CDMA MDN.
2423 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002424 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002425 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2427 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428
2429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002432 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433 return phone.getLine1Number();
2434 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002435 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 return null;
2437 }
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002440 }
2441 }
2442
2443 /**
2444 * Returns the CDMA MIN.
2445 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002446 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002447 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2449 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2455 return phone.getCdmaMin();
2456 } else {
2457 return null;
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002461 }
2462 }
2463
Hall Liud892bec2018-11-30 14:51:45 -08002464 @Override
2465 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2466 INumberVerificationCallback callback, String callingPackage) {
2467 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2468 != PERMISSION_GRANTED) {
2469 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2470 }
2471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2472
2473 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2474 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2475 throw new SecurityException("Calling package must be configured in the device config");
2476 }
2477
2478 if (range == null) {
2479 throw new NullPointerException("Range must be non-null");
2480 }
2481
2482 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002483 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002484
2485 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2486 }
2487
Junda Liuca05d5d2014-08-14 22:36:34 -07002488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 * Returns true if CDMA provisioning needs to run.
2490 */
2491 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 final long identity = Binder.clearCallingIdentity();
2493 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002494 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 }
2499
2500 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002501 * Sets the voice mail number of a given subId.
2502 */
2503 @Override
2504 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002505 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506
2507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2510 new Pair<String, String>(alphaTag, number), new Integer(subId));
2511 return success;
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002515 }
2516
Ta-wei Yen87c49842016-05-13 21:19:52 -07002517 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002518 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002520 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002521 if (!TextUtils.equals(callingPackage, systemDialer)) {
2522 throw new SecurityException("caller must be system dialer");
2523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2528 if (phoneAccountHandle == null) {
2529 return null;
2530 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002531 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002534 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002535 }
2536
2537 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002538 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002541 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002542 return null;
2543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002545 final long identity = Binder.clearCallingIdentity();
2546 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002547 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002551 }
2552
2553 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002554 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2555 VisualVoicemailSmsFilterSettings settings) {
2556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002561 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002565 }
2566
2567 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002568 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002574 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002578 }
2579
2580 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002581 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2582 String callingPackage, int subId) {
2583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002588 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002592 }
2593
2594 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002595 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002596 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002601 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 } finally {
2603 Binder.restoreCallingIdentity(identity);
2604 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002605 }
2606
2607 @Override
2608 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2609 String number, int port, String text, PendingIntent sentIntent) {
2610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002611 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002612 enforceSendSmsPermission();
2613 // Make the calls as the phone process.
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2617 if (port == 0) {
2618 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2619 sentIntent, null, false);
2620 } else {
2621 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2622 smsManager.sendDataMessageWithSelfPermissions(number, null,
2623 (short) port, data, sentIntent, null);
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002628 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002629 /**
fionaxu0152e512016-11-14 13:36:14 -08002630 * Sets the voice activation state of a given subId.
2631 */
2632 @Override
2633 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2635 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
2641 phone.setVoiceActivationState(activationState);
2642 } else {
2643 loge("setVoiceActivationState fails with invalid subId: " + subId);
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002647 }
2648 }
2649
2650 /**
2651 * Sets the data activation state of a given subId.
2652 */
2653 @Override
2654 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2656 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 final Phone phone = getPhone(subId);
2661 if (phone != null) {
2662 phone.setDataActivationState(activationState);
2663 } else {
2664 loge("setVoiceActivationState fails with invalid subId: " + subId);
2665 }
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002668 }
2669 }
2670
2671 /**
2672 * Returns the voice activation state of a given subId.
2673 */
2674 @Override
2675 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002676 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677
fionaxu0152e512016-11-14 13:36:14 -08002678 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 if (phone != null) {
2682 return phone.getVoiceActivationState();
2683 } else {
2684 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002688 }
2689 }
2690
2691 /**
2692 * Returns the data activation state of a given subId.
2693 */
2694 @Override
2695 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002696 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
fionaxu0152e512016-11-14 13:36:14 -08002698 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 if (phone != null) {
2702 return phone.getDataActivationState();
2703 } else {
2704 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2705 }
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002708 }
2709 }
2710
2711 /**
Wink Saville36469e72014-06-11 15:17:00 -07002712 * Returns the unread count of voicemails for a subId
2713 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002715 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2717 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2718 return 0;
2719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(subId);
2723 if (phone != null) {
2724 return phone.getVoiceMessageCount();
2725 } else {
2726 return 0;
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
2732
2733 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002734 * returns true, if the device is in a state where both voice and data
2735 * are supported simultaneously. This can change based on location or network condition.
2736 */
2737 @Override
2738 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = getPhone(subId);
2742 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
2745 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002746 }
2747
2748 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002749 * Send the dialer code if called from the current default dialer or the caller has
2750 * carrier privilege.
2751 * @param inputCode The dialer code to send
2752 */
2753 @Override
2754 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002755 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2758 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002759 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002760 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2761 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002766 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 } finally {
2768 Binder.restoreCallingIdentity(identity);
2769 }
fionaxu235cc5e2017-03-06 22:25:57 -08002770 }
2771
2772 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002773 * Returns the data network type.
2774 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 *
2776 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2777 */
2778 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002779 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(getDefaultSubscription());
2783 if (phone != null) {
2784 return phone.getServiceState().getDataNetworkType();
2785 } else {
2786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002790 }
Wink Saville36469e72014-06-11 15:17:00 -07002791 }
2792
Pengquan Menga1bb6272018-09-06 09:59:22 -07002793 @Override
2794 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002795 if (!isActiveSubscription(subId)) {
2796 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2797 }
2798
Pengquan Menga1bb6272018-09-06 09:59:22 -07002799 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2800 }
2801
Brad Ebinger35c841c2018-10-01 10:40:55 -07002802 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002803 public boolean isInEmergencySmsMode() {
2804 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 for (Phone phone : PhoneFactory.getPhones()) {
2808 if (phone.isInEmergencySmsMode()) {
2809 return true;
2810 }
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
2815 return false;
2816 }
2817
2818 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002819 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2820 throws RemoteException {
2821 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002822 final long token = Binder.clearCallingIdentity();
2823 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002826 .addRegistrationCallbackForSubscription(c, subId);
2827 } finally {
2828 Binder.restoreCallingIdentity(token);
2829 }
2830 }
2831
2832 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002833 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2834 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2836 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2837 }
2838 Binder.withCleanCallingIdentity(() -> {
2839 try {
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002842 .removeRegistrationCallbackForSubscription(c, subId);
2843 } catch (IllegalArgumentException e) {
2844 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2845 + "is inactive, ignoring unregister.");
2846 // If the subscription is no longer active, just return, since the callback
2847 // will already have been removed internally.
2848 }
2849 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002850 }
2851
2852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002853 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2854 throws RemoteException {
2855 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2857 final long token = Binder.clearCallingIdentity();
2858 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002860 .addCapabilitiesCallbackForSubscription(c, subId);
2861 } finally {
2862 Binder.restoreCallingIdentity(token);
2863 }
2864 }
2865
2866 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002867 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2868 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002869
2870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2871 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2872 }
2873 Binder.withCleanCallingIdentity(() -> {
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002877 .removeCapabilitiesCallbackForSubscription(c, subId);
2878 } catch (IllegalArgumentException e) {
2879 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2880 + "is inactive, ignoring unregister.");
2881 // If the subscription is no longer active, just return, since the callback
2882 // will already have been removed internally.
2883 }
2884 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002885 }
2886
2887 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002888 public boolean isCapable(int subId, int capability, int regTech) {
2889 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2891 final long token = Binder.clearCallingIdentity();
2892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002893 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2895 } catch (ImsException e) {
2896 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2897 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002898 } catch (IllegalArgumentException e) {
2899 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2900 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002901 } finally {
2902 Binder.restoreCallingIdentity(token);
2903 }
2904 }
2905
2906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002907 public boolean isAvailable(int subId, int capability, int regTech) {
2908 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002909 final long token = Binder.clearCallingIdentity();
2910 try {
2911 Phone phone = getPhone(subId);
2912 if (phone == null) return false;
2913 return phone.isImsCapabilityAvailable(capability, regTech);
2914 } finally {
2915 Binder.restoreCallingIdentity(token);
2916 }
2917 }
2918
2919 @Override
2920 public boolean isAdvancedCallingSettingEnabled(int subId) {
2921 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2923 final long token = Binder.clearCallingIdentity();
2924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2927 } finally {
2928 Binder.restoreCallingIdentity(token);
2929 }
2930 }
2931
2932 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002933 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002935 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002939 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002940 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
2944 }
2945
2946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002947 public boolean isVtSettingEnabled(int subId) {
2948 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 getSlotIndexOrException(subId)).isVtEnabledByUser();
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
2957 }
2958
2959 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002960 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002962 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002966 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public boolean isVoWiFiSettingEnabled(int subId) {
2974 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002986 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002988 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
2999 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3000 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003012 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003014 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003018 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
3023 }
3024
3025 @Override
3026 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3028 "setVoWiFiNonPersistent");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003032 boolean isRoaming = TelephonyManager.from(
3033 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003035 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public int getVoWiFiModeSetting(int subId) {
3043 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003047 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003048 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public void setVoWiFiModeSetting(int subId, int mode) {
3056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3057 "setVoWiFiModeSetting");
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
3066 }
3067
3068 @Override
3069 public int getVoWiFiRoamingModeSetting(int subId) {
3070 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
3081 @Override
3082 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3084 "setVoWiFiRoamingModeSetting");
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
3093 }
3094
3095 @Override
3096 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3098 "setRttCapabilityEnabled");
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003102 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
3107 }
3108
3109 @Override
3110 public boolean isTtyOverVolteEnabled(int subId) {
3111 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003115 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003122 @Override
3123 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3124 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003128 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003129 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
3135 @Override
3136 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3137 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3138 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003139 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3140 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3141 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003145 .removeProvisioningCallbackForSubscription(callback, subId);
3146 } catch (IllegalArgumentException e) {
3147 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3148 + "is inactive, ignoring unregister.");
3149 // If the subscription is no longer active, just return, since the callback will already
3150 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003157 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3158 boolean isProvisioned) {
3159 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3160 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3161 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3162 }
3163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3164 "setProvisioningStatusForCapability");
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3168 Phone phone = getPhone(subId);
3169 if (phone == null) {
3170 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3171 + subId);
3172 return;
3173 }
3174 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3175 return;
3176 }
3177
3178 // this capability requires provisioning, route to the correct API.
3179 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3180 switch (capability) {
3181 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3182 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3183 ims.setVolteProvisioned(isProvisioned);
3184 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3185 ims.setWfcProvisioned(isProvisioned);
3186 }
3187 break;
3188 }
3189 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3190 // There is currently no difference in VT provisioning type.
3191 ims.setVtProvisioned(isProvisioned);
3192 break;
3193 }
3194 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3195 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3196 // change the capability of the feature instead if needed.
3197 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3198 == isProvisioned) {
3199 // No change in provisioning.
3200 return;
3201 }
3202 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3203 try {
3204 ims.changeMmTelCapability(capability, tech, isProvisioned);
3205 } catch (ImsException e) {
3206 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3207 + ", Exception" + e.getMessage());
3208 }
3209 break;
3210 }
3211 default: {
3212 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3213 + capability + "', which does not require provisioning.");
3214 }
3215 }
3216
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 }
3221
3222 @Override
3223 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3224 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3225 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3226 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3227 }
3228 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3232 Phone phone = getPhone(subId);
3233 if (phone == null) {
3234 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3235 + subId);
3236 // We will fail with "true" as the provisioning status because this is the default
3237 // if we do not require provisioning.
3238 return true;
3239 }
3240
3241 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3242 return true;
3243 }
3244
3245 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3246 switch (capability) {
3247 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3248 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3249 return ims.isVolteProvisionedOnDevice();
3250 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3251 return ims.isWfcProvisionedOnDevice();
3252 }
3253 // This should never happen, since we are checking tech above to make sure it
3254 // is either LTE or IWLAN.
3255 throw new IllegalArgumentException("Invalid radio technology for voice "
3256 + "capability.");
3257 }
3258 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3259 // There is currently no difference in VT provisioning type.
3260 return ims.isVtProvisionedOnDevice();
3261 }
3262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3263 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3264 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3265 }
3266 default: {
3267 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3268 + capability + "', which does not require provisioning.");
3269 }
3270 }
3271
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
3275 }
3276
3277 @Override
3278 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3279 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3280 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3281 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3282 }
3283 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3284 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3285 return (provisionedBits & capability) > 0;
3286 }
3287
3288 @Override
3289 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3290 boolean isProvisioned) {
3291 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3292 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3293 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3294 }
3295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3296 "setProvisioningStatusForCapability");
3297 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3298 // If the current provisioning status for capability already matches isProvisioned,
3299 // do nothing.
3300 if (((provisionedBits & capability) > 0) == isProvisioned) {
3301 return;
3302 }
3303 if (isProvisioned) {
3304 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3305 } else {
3306 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3307 }
3308 }
3309
3310 /**
3311 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3312 * technology. The bitfield should mirror the bitfield defined by
3313 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3314 */
3315 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3316 String key = getMmTelProvisioningKey(subId, tech);
3317 // Default is no capabilities are provisioned.
3318 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3319 }
3320
3321 /**
3322 * Sets the MmTel capability provisioning bitfield (defined by
3323 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3324 * technology specified.
3325 *
3326 * Note: This is a synchronous command and should not be called on UI thread.
3327 */
3328 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3329 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3330 String key = getMmTelProvisioningKey(subId, tech);
3331 editor.putInt(key, newField);
3332 editor.commit();
3333 }
3334
3335 private static String getMmTelProvisioningKey(int subId, int tech) {
3336 // resulting key is provision_ims_mmtel_{subId}_{tech}
3337 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3338 }
3339
3340 /**
3341 * Query CarrierConfig to see if the specified capability requires provisioning for the
3342 * carrier associated with the subscription id.
3343 */
3344 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3345 int capability) {
3346 CarrierConfigManager configManager = new CarrierConfigManager(context);
3347 PersistableBundle c = configManager.getConfigForSubId(subId);
3348 boolean requireUtProvisioning = c.getBoolean(
3349 // By default, this config is true (even if there is no SIM). We also check to make
3350 // sure the subscription needs provisioning here, so we do not need to check for
3351 // the no-SIM case, where we would normally shortcut this to false.
3352 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3353 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3354 false);
3355 boolean requireVoiceVtProvisioning = c.getBoolean(
3356 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3357
3358 // First check to make sure that the capability requires provisioning.
3359 switch (capability) {
3360 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3361 // intentional fallthrough
3362 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3363 if (requireVoiceVtProvisioning) {
3364 // Voice and Video requires provisioning
3365 return true;
3366 }
3367 break;
3368 }
3369 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3370 if (requireUtProvisioning) {
3371 // UT requires provisioning
3372 return true;
3373 }
3374 break;
3375 }
3376 }
3377 return false;
3378 }
3379
3380 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003381 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003382 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3383 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3384 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003385 enforceReadPrivilegedPermission("getImsProvisioningInt");
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003389 int slotId = getSlotIndex(subId);
3390 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3391 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3392 + subId + "' for key:" + key);
3393 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3394 }
3395 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003397 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3398 + subId + "' for key:" + key);
3399 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
3405 @Override
3406 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003407 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3408 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3409 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 enforceReadPrivilegedPermission("getImsProvisioningString");
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003414 int slotId = getSlotIndex(subId);
3415 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3416 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3417 + subId + "' for key:" + key);
3418 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3419 }
3420 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3423 + subId + "' for key:" + key);
3424 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
3428 }
3429
3430 @Override
3431 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003432 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3433 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3434 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3436 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 int slotId = getSlotIndex(subId);
3441 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3442 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3443 + subId + "' for key:" + key);
3444 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3445 }
3446 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003448 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3449 + "' for key:" + key);
3450 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
3454 }
3455
3456 @Override
3457 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3459 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3460 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3462 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003466 int slotId = getSlotIndex(subId);
3467 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3468 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3469 + subId + "' for key:" + key);
3470 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3471 }
3472 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003473 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3475 + "' for key:" + key);
3476 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
3480 }
3481
Brad Ebinger35c841c2018-10-01 10:40:55 -07003482 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3483 int slotId = SubscriptionManager.getSlotIndex(subId);
3484 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003485 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 }
3487 return slotId;
3488 }
3489
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 private int getSlotIndex(int subId) {
3491 int slotId = SubscriptionManager.getSlotIndex(subId);
3492 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3493 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3494 }
3495 return slotId;
3496 }
3497
Wink Saville36469e72014-06-11 15:17:00 -07003498 /**
3499 * Returns the network type for a subId
3500 */
3501 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003502 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003504 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003505 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3506 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 final Phone phone = getPhone(subId);
3511 if (phone != null) {
3512 return phone.getServiceState().getDataNetworkType();
3513 } else {
3514 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3515 }
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 }
3520
3521 /**
3522 * Returns the data network type
3523 */
3524 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 public int getDataNetworkType(String callingPackage) {
3526 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003527 }
3528
3529 /**
3530 * Returns the data network type for a subId
3531 */
3532 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003535 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003536 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3537 }
3538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 final Phone phone = getPhone(subId);
3542 if (phone != null) {
3543 return phone.getServiceState().getDataNetworkType();
3544 } else {
3545 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3546 }
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003550 }
3551
3552 /**
Wink Saville36469e72014-06-11 15:17:00 -07003553 * Returns the Voice network type for a subId
3554 */
3555 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003556 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003558 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003559 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3560 }
3561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 return phone.getServiceState().getVoiceNetworkType();
3567 } else {
3568 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 }
3574
3575 /**
3576 * @return true if a ICC card is present
3577 */
3578 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003579 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003580 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3581 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003582 }
3583
3584 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003585 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003586 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003588 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = PhoneFactory.getPhone(slotIndex);
3592 if (phone != null) {
3593 return phone.getIccCard().hasIccCard();
3594 } else {
3595 return false;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003600 }
3601
3602 /**
3603 * Return if the current radio is LTE on CDMA. This
3604 * is a tri-state return value as for a period of time
3605 * the mode may be unknown.
3606 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003607 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003609 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003611 @Override
3612 public int getLteOnCdmaMode(String callingPackage) {
3613 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003614 }
3615
Sanket Padawe356d7632015-06-22 14:03:32 -07003616 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003617 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003619 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003620 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3621 }
3622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 final Phone phone = getPhone(subId);
3626 if (phone == null) {
3627 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3628 } else {
3629 return phone.getLteOnCdmaMode();
3630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 }
Wink Saville36469e72014-06-11 15:17:00 -07003634 }
3635
Wink Saville36469e72014-06-11 15:17:00 -07003636 /**
3637 * {@hide}
3638 * Returns Default subId, 0 in the case of single standby.
3639 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003640 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003641 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003642 }
3643
Shishir Agrawala9f32182016-04-12 12:00:16 -07003644 private int getSlotForDefaultSubscription() {
3645 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3646 }
3647
Wink Savilleb564aae2014-10-23 10:18:09 -07003648 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003649 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003651
Pengquan Menge92a50d2018-09-21 15:54:48 -07003652 private boolean isActiveSubscription(int subId) {
3653 return mSubscriptionController.isActiveSubId(subId);
3654 }
3655
Ihab Awadf2177b72013-11-25 13:33:23 -08003656 /**
3657 * @see android.telephony.TelephonyManager.WifiCallingChoices
3658 */
3659 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3664 getWhenToMakeWifiCallsDefaultPreference());
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003668 }
3669
3670 /**
3671 * @see android.telephony.TelephonyManager.WifiCallingChoices
3672 */
3673 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003682 }
3683
Sailesh Nepald1e68152013-12-12 19:08:02 -08003684 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003685 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003686 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003687 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003688
Jordan Liu4c733742019-02-28 12:03:40 -08003689 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3690 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3691 if (phoneId == -1) {
3692 throw new IllegalArgumentException("Given slot index: " + slotIndex
3693 + " does not correspond to an active phone");
3694 }
3695 return PhoneFactory.getPhone(phoneId);
3696 }
3697
Shishir Agrawal566b7612013-10-28 14:41:00 -07003698 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003699 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3700 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3702 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003704 if (DBG) {
3705 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3706 }
3707 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3708 p2);
3709 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003710
Jordan Liu4c733742019-02-28 12:03:40 -08003711
3712 @Override
3713 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3714 int slotIndex, String callingPackage, String aid, int p2) {
3715 enforceModifyPermission();
3716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3717 if (DBG) {
3718 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3719 }
3720 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3721 callingPackage, aid, p2);
3722 }
3723
3724 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3725 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 if (TextUtils.equals(ISDR_AID, aid)) {
3729 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003730 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3731 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 if (bestComponent == null
3733 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3734 loge("The calling package is not allowed to access ISD-R.");
3735 throw new SecurityException(
3736 "The calling package is not allowed to access ISD-R.");
3737 }
Derek Tan740e1672017-06-27 14:56:27 -07003738 }
Derek Tan740e1672017-06-27 14:56:27 -07003739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003741 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3742 null /* workSource */);
3743 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 return response;
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003748 }
3749
3750 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003751 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3753 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003754 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3755 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3756 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003757
Jordan Liu4c733742019-02-28 12:03:40 -08003758 @Override
3759 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3760 enforceModifyPermission();
3761 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3762 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3763 channel);
3764 }
3765
3766 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767 final long identity = Binder.clearCallingIdentity();
3768 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 if (channel < 0) {
3770 return false;
3771 }
Jordan Liu4c733742019-02-28 12:03:40 -08003772 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3773 null /* workSource */);
3774 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775 return success;
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003778 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003779 }
3780
3781 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003782 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003783 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3785 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003786 if (DBG) {
3787 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3788 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3789 + p3 + " data=" + data);
3790 }
3791 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3792 command, p1, p2, p3, data);
3793 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003794
Jordan Liu4c733742019-02-28 12:03:40 -08003795 @Override
3796 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3797 int command, int p1, int p2, int p3, String data) {
3798 enforceModifyPermission();
3799 if (DBG) {
3800 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3801 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3802 + p3 + " data=" + data);
3803 }
3804 return iccTransmitApduLogicalChannelWithPermission(
3805 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3806 data);
3807 }
3808
3809 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3810 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 if (channel < 0) {
3814 return "";
3815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003818 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3819 null /* workSource */);
3820 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822 // Append the returned status code to the end of the response payload.
3823 String s = Integer.toHexString(
3824 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3825 if (response.payload != null) {
3826 s = IccUtils.bytesToHexString(response.payload) + s;
3827 }
3828 return s;
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003832 }
Jake Hambye994d462014-02-03 13:10:13 -08003833
Evan Charltonc66da362014-05-16 14:06:40 -07003834 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003835 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3836 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3838 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003840 if (DBG) {
3841 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3842 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3843 }
3844 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3845 cla, command, p1, p2, p3, data);
3846 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003847
Jordan Liu4c733742019-02-28 12:03:40 -08003848 @Override
3849 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3850 int command, int p1, int p2, int p3, String data) {
3851 enforceModifyPermission();
3852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3853 if (DBG) {
3854 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3855 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3856 + " data=" + data);
3857 }
3858
3859 return iccTransmitApduBasicChannelWithPermission(
3860 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3861 p2, p3, data);
3862 }
3863
3864 // open APDU basic channel assuming the caller has sufficient permissions
3865 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3866 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3870 && TextUtils.equals(ISDR_AID, data)) {
3871 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003872 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3873 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 if (bestComponent == null
3875 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3876 loge("The calling package is not allowed to select ISD-R.");
3877 throw new SecurityException(
3878 "The calling package is not allowed to select ISD-R.");
3879 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003880 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003883 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3884 null /* workSource */);
3885 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 // Append the returned status code to the end of the response payload.
3888 String s = Integer.toHexString(
3889 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3890 if (response.payload != null) {
3891 s = IccUtils.bytesToHexString(response.payload) + s;
3892 }
3893 return s;
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003896 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003897 }
3898
3899 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003900 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003901 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3903 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 if (DBG) {
3908 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3909 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3910 }
3911
3912 IccIoResult response =
3913 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3914 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3915 subId);
3916
3917 if (DBG) {
3918 log("Exchange SIM_IO [R]" + response);
3919 }
3920
3921 byte[] result = null;
3922 int length = 2;
3923 if (response.payload != null) {
3924 length = 2 + response.payload.length;
3925 result = new byte[length];
3926 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3927 } else {
3928 result = new byte[length];
3929 }
3930
3931 result[length - 1] = (byte) response.sw2;
3932 result[length - 2] = (byte) response.sw1;
3933 return result;
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003937 }
3938
Nathan Haroldb3014052017-01-25 15:57:32 -08003939 /**
3940 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3941 * on a particular subscription
3942 */
sqianb6e41952018-03-12 14:54:01 -07003943 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3945 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3946 return null;
3947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 if (appType != TelephonyManager.APPTYPE_USIM
3952 && appType != TelephonyManager.APPTYPE_SIM) {
3953 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3954 return null;
3955 }
3956 Object response = sendRequest(
3957 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3958 if (response instanceof String[]) {
3959 return (String[]) response;
3960 }
3961 // Response is an Exception of some kind,
3962 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003963 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003966 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003967 }
3968
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003969 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003970 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3972 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3977 if (response.payload == null) {
3978 return "";
3979 }
Evan Charltonc66da362014-05-16 14:06:40 -07003980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 // Append the returned status code to the end of the response payload.
3982 String s = Integer.toHexString(
3983 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3984 s = IccUtils.bytesToHexString(response.payload) + s;
3985 return s;
3986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
Evan Charltonc66da362014-05-16 14:06:40 -07003989 }
3990
Jake Hambye994d462014-02-03 13:10:13 -08003991 /**
3992 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3993 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3994 *
3995 * @param itemID the ID of the item to read
3996 * @return the NV item as a String, or null on error.
3997 */
3998 @Override
3999 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4002 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004007 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4009 return value;
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Jake Hambye994d462014-02-03 13:10:13 -08004013 }
4014
4015 /**
4016 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4017 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4018 *
4019 * @param itemID the ID of the item to read
4020 * @param itemValue the value to write, as a String
4021 * @return true on success; false on any failure
4022 */
4023 @Override
4024 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4027 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4032 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004033 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4035 return success;
4036 } finally {
4037 Binder.restoreCallingIdentity(identity);
4038 }
Jake Hambye994d462014-02-03 13:10:13 -08004039 }
4040
4041 /**
4042 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4043 * Used for device configuration by some CDMA operators.
4044 *
4045 * @param preferredRoamingList byte array containing the new PRL
4046 * @return true on success; false on any failure
4047 */
4048 @Override
4049 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4051 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4056 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4057 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4058 return success;
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
Jake Hambye994d462014-02-03 13:10:13 -08004062 }
4063
4064 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004065 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004066 * Used for device configuration by some CDMA operators.
4067 *
chen xu6dac5ab2018-10-26 17:39:23 -07004068 * @param slotIndex - device slot.
4069 *
Jake Hambye994d462014-02-03 13:10:13 -08004070 * @return true on success; false on any failure
4071 */
4072 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004073 public boolean resetModemConfig(int slotIndex) {
4074 Phone phone = PhoneFactory.getPhone(slotIndex);
4075 if (phone != null) {
4076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4077 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078
chen xu6dac5ab2018-10-26 17:39:23 -07004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4082 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4083 return success;
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 }
chen xu6dac5ab2018-10-26 17:39:23 -07004088 return false;
4089 }
4090
4091 /**
4092 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4093 *
4094 * @param slotIndex - device slot.
4095 *
4096 * @return true on success; false on any failure
4097 */
4098 @Override
4099 public boolean rebootModem(int slotIndex) {
4100 Phone phone = PhoneFactory.getPhone(slotIndex);
4101 if (phone != null) {
4102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4103 mApp, phone.getSubId(), "rebootModem");
4104
4105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4108 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4109 return success;
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
4113 }
4114 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004115 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004116
Svet Ganovb320e182015-04-16 12:30:10 -07004117 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004121 return new String[0];
4122 }
4123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
Wink Saville36469e72014-06-11 15:17:00 -07004130 }
4131
Brad Ebinger51f743a2017-01-23 13:50:20 -08004132 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004133 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4134 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004135 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004136 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004141 ImsResolver resolver = PhoneFactory.getImsResolver();
4142 if (resolver == null) {
4143 // may happen if the device does not support IMS.
4144 return;
4145 }
4146 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004150 }
4151
4152 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004153 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4154 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004155 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004156 public void disableIms(int slotId) {
4157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004161 ImsResolver resolver = PhoneFactory.getImsResolver();
4162 if (resolver == null) {
4163 // may happen if the device does not support IMS.
4164 return;
4165 }
4166 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004170 }
4171
4172 /**
4173 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4174 * feature or {@link null} if the service is not available. If the feature is available, the
4175 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4176 */
4177 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004178 IImsServiceFeatureCallback callback) {
4179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
4181 final long identity = Binder.clearCallingIdentity();
4182 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004183 ImsResolver resolver = PhoneFactory.getImsResolver();
4184 if (resolver == null) {
4185 // may happen if the device does not support IMS.
4186 return null;
4187 }
4188 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004192 }
4193
4194 /**
4195 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4196 * feature during emergency calling or {@link null} if the service is not available. If the
4197 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4198 * listener for feature updates.
4199 */
4200 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4201 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202
4203 final long identity = Binder.clearCallingIdentity();
4204 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004205 ImsResolver resolver = PhoneFactory.getImsResolver();
4206 if (resolver == null) {
4207 // may happen if the device does not support IMS.
4208 return null;
4209 }
4210 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
4213 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004214 }
4215
Brad Ebinger5f64b052017-12-14 14:26:15 -08004216 /**
4217 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004218 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004219 */
4220 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004225 ImsResolver resolver = PhoneFactory.getImsResolver();
4226 if (resolver == null) {
4227 // may happen if the device does not support IMS.
4228 return null;
4229 }
4230 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004234 }
4235
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004236 /**
4237 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004238 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004239 */
4240 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242
4243 final long identity = Binder.clearCallingIdentity();
4244 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004245 ImsResolver resolver = PhoneFactory.getImsResolver();
4246 if (resolver == null) {
4247 // may happen if the device does not support IMS.
4248 return null;
4249 }
4250 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004254 }
4255
Brad Ebinger884c07b2018-02-15 16:17:40 -08004256 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004257 * Sets the ImsService Package Name that Telephony will bind to.
4258 *
4259 * @param slotId the slot ID that the ImsService should bind for.
4260 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4261 * ImsService is the device default ImsService.
4262 * @param packageName The package name of the application that contains the ImsService to bind
4263 * to.
4264 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4265 * @hide
4266 */
4267 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004268 int[] subIds = SubscriptionManager.getSubId(slotId);
4269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4270 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4271 "setImsService");
4272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004275 ImsResolver resolver = PhoneFactory.getImsResolver();
4276 if (resolver == null) {
4277 // may happen if the device does not support IMS.
4278 return false;
4279 }
4280 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4281 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004285 }
4286
4287 /**
4288 * Return the ImsService configuration.
4289 *
4290 * @param slotId The slot that the ImsService is associated with.
4291 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4292 * the device default.
4293 * @return the package name of the ImsService configuration.
4294 */
4295 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004296 int[] subIds = SubscriptionManager.getSubId(slotId);
4297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4298 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4299 "getImsService");
4300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004303 ImsResolver resolver = PhoneFactory.getImsResolver();
4304 if (resolver == null) {
4305 // may happen if the device does not support IMS.
4306 return "";
4307 }
4308 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004312 }
4313
Wink Saville36469e72014-06-11 15:17:00 -07004314 public void setImsRegistrationState(boolean registered) {
4315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004319 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Wink Saville36469e72014-06-11 15:17:00 -07004323 }
4324
4325 /**
Stuart Scott54788802015-03-30 13:18:01 -07004326 * Set the network selection mode to automatic.
4327 *
4328 */
4329 @Override
4330 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4332 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333
Pengquan Menge92a50d2018-09-21 15:54:48 -07004334 if (!isActiveSubscription(subId)) {
4335 return;
4336 }
4337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4341 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Stuart Scott54788802015-03-30 13:18:01 -07004345 }
4346
Pengquan Mengea84e042018-09-20 14:57:26 -07004347 /**
4348 * Ask the radio to connect to the input network and change selection mode to manual.
4349 *
4350 * @param subId the id of the subscription.
4351 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4352 * the operator to attach to.
4353 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4354 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4355 * normal network selection next time.
4356 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004357 */
4358 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004359 public boolean setNetworkSelectionModeManual(
4360 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4362 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004363
4364 if (!isActiveSubscription(subId)) {
4365 return false;
4366 }
4367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004370 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004372 if (DBG) {
4373 log("setNetworkSelectionModeManual: subId: " + subId
4374 + " operator: " + operatorInfo);
4375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004380 }
4381
4382 /**
4383 * Scans for available networks.
4384 */
4385 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004386 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4388 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004389 LocationAccessPolicy.LocationPermissionResult locationResult =
4390 LocationAccessPolicy.checkLocationPermission(mApp,
4391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4392 .setCallingPackage(callingPackage)
4393 .setCallingPid(Binder.getCallingPid())
4394 .setCallingUid(Binder.getCallingUid())
4395 .setMethod("getCellNetworkScanResults")
4396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4397 .build());
4398 switch (locationResult) {
4399 case DENIED_HARD:
4400 throw new SecurityException("Not allowed to access scan results -- location");
4401 case DENIED_SOFT:
4402 return null;
4403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404
Pengquan Menga1bb6272018-09-06 09:59:22 -07004405 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 try {
4407 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004408 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004413 }
4414
4415 /**
yinxub1bed742017-04-17 11:45:04 -07004416 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004417 *
yinxub1bed742017-04-17 11:45:04 -07004418 * @param subId id of the subscription
4419 * @param request contains the radio access networks with bands/channels to scan
4420 * @param messenger callback messenger for scan results or errors
4421 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004422 * @return the id of the requested scan which can be used to stop the scan.
4423 */
4424 @Override
4425 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004426 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004429 LocationAccessPolicy.LocationPermissionResult locationResult =
4430 LocationAccessPolicy.checkLocationPermission(mApp,
4431 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4432 .setCallingPackage(callingPackage)
4433 .setCallingPid(Binder.getCallingPid())
4434 .setCallingUid(Binder.getCallingUid())
4435 .setMethod("requestNetworkScan")
4436 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4437 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004438 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4439 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4440 if (e != null) {
4441 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4442 throw e;
4443 } else {
4444 return TelephonyScanManager.INVALID_SCAN_ID;
4445 }
4446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004448 return mNetworkScanRequestTracker.startNetworkScan(
4449 request, messenger, binder, getPhone(subId),
4450 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004451 }
4452
Hall Liub2ac8ef2019-02-28 15:56:23 -08004453 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4454 NetworkScanRequest request) {
4455 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4456 != PERMISSION_GRANTED) {
4457 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4458 + " without location access.");
4459 }
4460
4461 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4462 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
4463 if (ras.getBands() != null && ras.getBands().length > 0) {
4464 return new SecurityException("Specific bands must not be"
4465 + " scanned without location access.");
4466 }
4467 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4468 return new SecurityException("Specific channels must not be"
4469 + " scanned without location access.");
4470 }
4471 }
4472 }
4473
4474 List<String> allowedMccMncs =
4475 NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp);
4476 for (String mccmnc : request.getPlmns()) {
4477 if (!allowedMccMncs.contains(mccmnc)) {
4478 return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the"
4479 + " device and cannot be scanned for without location access.");
4480 }
4481 }
4482
4483 return null;
4484 }
4485
yinxu504e1392017-04-12 16:03:22 -07004486 /**
4487 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004488 *
4489 * @param subId id of the subscription
4490 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004491 */
4492 @Override
4493 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4495 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
yinxu504e1392017-04-12 16:03:22 -07004503 }
4504
4505 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004506 * Get the calculated preferred network type.
4507 * Used for debugging incorrect network type.
4508 *
4509 * @return the preferred network type, defined in RILConstants.java.
4510 */
4511 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004512 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004513 final Phone defaultPhone = getDefaultPhone();
4514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4515 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004516 return RILConstants.PREFERRED_NETWORK_MODE;
4517 }
4518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
4521 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004522 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
Junda Liu84d15a22014-07-02 11:21:04 -07004526 }
4527
4528 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004529 * Get the preferred network type.
4530 * Used for device configuration by some CDMA operators.
4531 *
4532 * @return the preferred network type, defined in RILConstants.java.
4533 */
4534 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004535 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004536 TelephonyPermissions
4537 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4538 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 if (DBG) log("getPreferredNetworkType");
4543 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4544 int networkType = (result != null ? result[0] : -1);
4545 if (DBG) log("getPreferredNetworkType: " + networkType);
4546 return networkType;
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004550 }
4551
4552 /**
4553 * Set the preferred network type.
4554 * Used for device configuration by some CDMA operators.
4555 *
4556 * @param networkType the preferred network type, defined in RILConstants.java.
4557 * @return true on success; false on any failure.
4558 */
4559 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004560 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4562 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4567 Boolean success = (Boolean) sendRequest(
4568 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4569 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4570 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004571 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4573 }
4574 return success;
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004577 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004578 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004579
4580 /**
Miaoa84611c2019-03-15 09:21:10 +08004581 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004582 *
Miaoa84611c2019-03-15 09:21:10 +08004583 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004584 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004585 * @hide
4586 */
4587 @Override
Miaoa84611c2019-03-15 09:21:10 +08004588 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 try {
Miaoa84611c2019-03-15 09:21:10 +08004593 if (phone != null) {
4594 return phone.hasMatchedTetherApnSetting();
4595 } else {
4596 return false;
4597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004600 }
Junda Liu475951f2014-11-07 16:45:03 -08004601 }
4602
4603 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004604 * Set mobile data enabled
4605 * Used by the user through settings etc to turn on/off mobile data
4606 *
4607 * @param enable {@code true} turn turn data on, else {@code false}
4608 */
4609 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004610 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4612 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 int phoneId = mSubscriptionController.getPhoneId(subId);
4617 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4618 Phone phone = PhoneFactory.getPhone(phoneId);
4619 if (phone != null) {
4620 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004621 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004623 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 }
4625 } finally {
4626 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004627 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004628 }
4629
4630 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004631 * Get the user enabled state of Mobile Data.
4632 *
4633 * TODO: remove and use isUserDataEnabled.
4634 * This can't be removed now because some vendor codes
4635 * calls through ITelephony directly while they should
4636 * use TelephonyManager.
4637 *
4638 * @return true on enabled
4639 */
4640 @Override
4641 public boolean getDataEnabled(int subId) {
4642 return isUserDataEnabled(subId);
4643 }
4644
4645 /**
4646 * Get whether mobile data is enabled per user setting.
4647 *
4648 * There are other factors deciding whether mobile data is actually enabled, but they are
4649 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004650 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004651 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004652 *
4653 * @return {@code true} if data is enabled else {@code false}
4654 */
4655 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004656 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004657 try {
4658 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4659 null);
4660 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4662 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 int phoneId = mSubscriptionController.getPhoneId(subId);
4668 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4669 Phone phone = PhoneFactory.getPhone(phoneId);
4670 if (phone != null) {
4671 boolean retVal = phone.isUserDataEnabled();
4672 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4673 return retVal;
4674 } else {
4675 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4676 return false;
4677 }
4678 } finally {
4679 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004680 }
4681 }
4682
4683 /**
4684 * Get whether mobile data is enabled.
4685 *
4686 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4687 * whether mobile data is actually enabled.
4688 *
4689 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4690 *
4691 * @return {@code true} if data is enabled else {@code false}
4692 */
4693 @Override
4694 public boolean isDataEnabled(int subId) {
4695 try {
4696 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4697 null);
4698 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4700 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 int phoneId = mSubscriptionController.getPhoneId(subId);
4706 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4707 Phone phone = PhoneFactory.getPhone(phoneId);
4708 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004709 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4711 return retVal;
4712 } else {
4713 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4714 return false;
4715 }
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004718 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004719 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004720
4721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004722 public int getCarrierPrivilegeStatus(int subId) {
4723 final Phone phone = getPhone(subId);
4724 if (phone == null) {
4725 loge("getCarrierPrivilegeStatus: Invalid subId");
4726 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4727 }
4728 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004729 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004730 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004731 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4732 }
4733 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004734 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004735 }
Junda Liu29340342014-07-10 15:23:27 -07004736
4737 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4739 final Phone phone = getPhone(subId);
4740 if (phone == null) {
4741 loge("getCarrierPrivilegeStatus: Invalid subId");
4742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4743 }
4744 UiccProfile profile =
4745 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4746 if (profile == null) {
4747 loge("getCarrierPrivilegeStatus: No UICC");
4748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4749 }
4750 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4751 }
4752
4753 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004754 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004755 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004756 if (TextUtils.isEmpty(pkgName))
4757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004758 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004759 if (card == null) {
4760 loge("checkCarrierPrivilegesForPackage: No UICC");
4761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4762 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004763 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4764 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004765 }
4766
4767 @Override
4768 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004769 if (TextUtils.isEmpty(pkgName))
4770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004771 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4772 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4773 UiccCard card = UiccController.getInstance().getUiccCard(i);
4774 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004775 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004776 continue;
4777 }
4778
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004779 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004780 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4781 break;
4782 }
4783 }
4784
4785 return result;
Junda Liu29340342014-07-10 15:23:27 -07004786 }
Derek Tan89e89d42014-07-08 17:00:10 -07004787
4788 @Override
Junda Liue64de782015-04-16 17:19:16 -07004789 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4790 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4791 loge("phoneId " + phoneId + " is not valid.");
4792 return null;
4793 }
4794 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004795 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004796 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004797 return null ;
4798 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004799 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004800 }
4801
Amith Yamasani6e118872016-02-19 12:53:51 -08004802 @Override
4803 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004804 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004805 List<String> privilegedPackages = new ArrayList<>();
4806 List<PackageInfo> packages = null;
4807 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4808 UiccCard card = UiccController.getInstance().getUiccCard(i);
4809 if (card == null) {
4810 // No UICC in that slot.
4811 continue;
4812 }
4813 if (card.hasCarrierPrivilegeRules()) {
4814 if (packages == null) {
4815 // Only check packages in user 0 for now
4816 packages = pm.getInstalledPackagesAsUser(
4817 PackageManager.MATCH_DISABLED_COMPONENTS
4818 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4819 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4820 }
4821 for (int p = packages.size() - 1; p >= 0; p--) {
4822 PackageInfo pkgInfo = packages.get(p);
4823 if (pkgInfo != null && pkgInfo.packageName != null
4824 && card.getCarrierPrivilegeStatus(pkgInfo)
4825 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4826 privilegedPackages.add(pkgInfo.packageName);
4827 }
4828 }
4829 }
4830 }
4831 return privilegedPackages;
4832 }
4833
Wink Savilleb564aae2014-10-23 10:18:09 -07004834 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004835 final Phone phone = getPhone(subId);
4836 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004837 if (card == null) {
4838 loge("getIccId: No UICC");
4839 return null;
4840 }
4841 String iccId = card.getIccId();
4842 if (TextUtils.isEmpty(iccId)) {
4843 loge("getIccId: ICC ID is null or empty.");
4844 return null;
4845 }
4846 return iccId;
4847 }
4848
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004849 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004850 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4851 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004852 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4853 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 final String iccId = getIccId(subId);
4858 final Phone phone = getPhone(subId);
4859 if (phone == null) {
4860 return false;
4861 }
4862 final String subscriberId = phone.getSubscriberId();
4863
4864 if (DBG_MERGE) {
4865 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4866 + subscriberId + " to " + number);
4867 }
4868
4869 if (TextUtils.isEmpty(iccId)) {
4870 return false;
4871 }
4872
4873 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4874
4875 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4876 if (alphaTag == null) {
4877 editor.remove(alphaTagPrefKey);
4878 } else {
4879 editor.putString(alphaTagPrefKey, alphaTag);
4880 }
4881
4882 // Record both the line number and IMSI for this ICCID, since we need to
4883 // track all merged IMSIs based on line number
4884 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4885 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4886 if (number == null) {
4887 editor.remove(numberPrefKey);
4888 editor.remove(subscriberPrefKey);
4889 } else {
4890 editor.putString(numberPrefKey, number);
4891 editor.putString(subscriberPrefKey, subscriberId);
4892 }
4893
4894 editor.commit();
4895 return true;
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004898 }
Derek Tan7226c842014-07-02 17:42:23 -07004899 }
4900
4901 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004902 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004903 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004905 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004906 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004907 return null;
4908 }
Derek Tan97ebb422014-09-05 16:55:38 -07004909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 String iccId = getIccId(subId);
4913 if (iccId != null) {
4914 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4915 if (DBG_MERGE) {
4916 log("getLine1NumberForDisplay returning "
4917 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4918 }
4919 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4922 return null;
4923 } finally {
4924 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004925 }
Derek Tan7226c842014-07-02 17:42:23 -07004926 }
4927
4928 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004929 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004931 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004932 return null;
4933 }
Derek Tan97ebb422014-09-05 16:55:38 -07004934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 String iccId = getIccId(subId);
4938 if (iccId != null) {
4939 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4940 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4941 }
4942 return null;
4943 } finally {
4944 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004945 }
Derek Tan7226c842014-07-02 17:42:23 -07004946 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004947
4948 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004949 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004950 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4951 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004953 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4954 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004955 return null;
4956 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004957
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004960 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 final TelephonyManager tele = TelephonyManager.from(context);
4962 final SubscriptionManager sub = SubscriptionManager.from(context);
4963
4964 // Figure out what subscribers are currently active
4965 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4966 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4967 // the process, where TelephonyManager was instantiated.
4968 // Otherwise AppOps check will fail.
4969
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004970 final int[] subIds = sub.getActiveSubscriptionIdList();
4971 for (int subId : subIds) {
4972 activeSubscriberIds.add(tele.getSubscriberId(subId));
4973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 // First pass, find a number override for an active subscriber
4976 String mergeNumber = null;
4977 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4978 for (String key : prefs.keySet()) {
4979 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4980 final String subscriberId = (String) prefs.get(key);
4981 if (activeSubscriberIds.contains(subscriberId)) {
4982 final String iccId = key.substring(
4983 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4984 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4985 mergeNumber = (String) prefs.get(numberKey);
4986 if (DBG_MERGE) {
4987 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4988 + " for active subscriber " + subscriberId);
4989 }
4990 if (!TextUtils.isEmpty(mergeNumber)) {
4991 break;
4992 }
4993 }
4994 }
4995 }
4996
4997 // Shortcut when no active merged subscribers
4998 if (TextUtils.isEmpty(mergeNumber)) {
4999 return null;
5000 }
5001
5002 // Second pass, find all subscribers under that line override
5003 final ArraySet<String> result = new ArraySet<>();
5004 for (String key : prefs.keySet()) {
5005 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5006 final String number = (String) prefs.get(key);
5007 if (mergeNumber.equals(number)) {
5008 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5009 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5010 final String subscriberId = (String) prefs.get(subscriberKey);
5011 if (!TextUtils.isEmpty(subscriberId)) {
5012 result.add(subscriberId);
5013 }
5014 }
5015 }
5016 }
5017
5018 final String[] resultArray = result.toArray(new String[result.size()]);
5019 Arrays.sort(resultArray);
5020 if (DBG_MERGE) {
5021 Slog.d(LOG_TAG,
5022 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5023 }
5024 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005027 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005028 }
5029
5030 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005031 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005032 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5033 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005042 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005043
5044 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005045 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005046 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5047 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005048 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 final Phone phone = getPhone(subId);
5053 if (phone == null) {
5054 return false;
5055 }
5056 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5057 cdmaNonRoamingList);
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005060 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005061 }
5062
5063 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005064 @Deprecated
5065 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5066 enforceModifyPermission();
5067
5068 int returnValue = 0;
5069 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005070 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005071 if(result.exception == null) {
5072 if (result.result != null) {
5073 byte[] responseData = (byte[])(result.result);
5074 if(responseData.length > oemResp.length) {
5075 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5076 responseData.length + "bytes. Buffer Size is " +
5077 oemResp.length + "bytes.");
5078 }
5079 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5080 returnValue = responseData.length;
5081 }
5082 } else {
5083 CommandException ex = (CommandException) result.exception;
5084 returnValue = ex.getCommandError().ordinal();
5085 if(returnValue > 0) returnValue *= -1;
5086 }
5087 } catch (RuntimeException e) {
5088 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5089 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5090 if(returnValue > 0) returnValue *= -1;
5091 }
5092
5093 return returnValue;
5094 }
5095
5096 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005097 public void setRadioCapability(RadioAccessFamily[] rafs) {
5098 try {
5099 ProxyController.getInstance().setRadioCapability(rafs);
5100 } catch (RuntimeException e) {
5101 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5102 }
5103 }
5104
5105 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005106 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005107 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005108 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005109 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005110 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
chen xub97461a2018-10-26 14:17:57 -07005114 TelephonyPermissions
5115 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5116 mApp, phone.getSubId(), "getRadioAccessFamily");
5117 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 } finally {
5119 Binder.restoreCallingIdentity(identity);
5120 }
chen xub97461a2018-10-26 14:17:57 -07005121 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005122 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005123
5124 @Override
5125 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005126 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005127 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128
5129 final long identity = Binder.clearCallingIdentity();
5130 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005131 ImsManager.getInstance(defaultPhone.getContext(),
5132 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005136 }
5137
5138 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005139 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005140 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005142 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005143 return false;
5144 }
Svet Ganovb320e182015-04-16 12:30:10 -07005145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 // Check the user preference and the system-level IMS setting. Even if the user has
5149 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5150 // In the long run, we may instead need to check if there exists a connection service
5151 // which can support video calling.
5152 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005153 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 return imsManager.isVtEnabledByPlatform()
5155 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5156 && imsManager.isVtEnabledByUser();
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005160 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005161
Andrew Leea1239f22015-03-02 17:44:07 -08005162 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5165 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5166 return false;
5167 }
5168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 CarrierConfigManager configManager =
5172 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005173 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Andrew Leea1239f22015-03-02 17:44:07 -08005178 }
5179
5180 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 public boolean isWorldPhone(int subId, String callingPackage) {
5182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5183 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5184 return false;
5185 }
5186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 CarrierConfigManager configManager =
5190 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
Andrew Leea1239f22015-03-02 17:44:07 -08005196 }
5197
Andrew Lee9431b832015-03-09 18:46:45 -07005198 @Override
5199 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005200 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005201 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005202 }
5203
5204 @Override
5205 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 final long identity = Binder.clearCallingIdentity();
5207 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Andrew Lee9431b832015-03-09 18:46:45 -07005212 }
5213
Hall Liuf6668912018-10-31 17:05:23 -07005214 /**
5215 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5216 * support for the feature and device firmware support.
5217 *
5218 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5219 */
5220 @Override
5221 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005223 final Phone phone = getPhone(subscriptionId);
5224 if (phone == null) {
5225 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5226 return false;
5227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005229 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5231 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005232 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 return isCarrierSupported && isDeviceSupported;
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Hall Liu98187582018-01-22 19:15:32 -08005237 }
5238
Hall Liuf6668912018-10-31 17:05:23 -07005239 /**
5240 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5241 * both also support RTT.
5242 */
5243 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Hall Liuf6668912018-10-31 17:05:23 -07005246 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005247 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005251 }
5252
Sanket Padawe7310cc72015-01-14 09:53:20 -08005253 /**
5254 * Returns the unique device ID of phone, for example, the IMEI for
5255 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5256 *
5257 * <p>Requires Permission:
5258 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5259 */
5260 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005261 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005262 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005263 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005264 return null;
5265 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005266 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005267 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5268 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005269 return null;
5270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 return phone.getDeviceId();
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005278 }
5279
Ping Sunc67b7c22016-03-02 19:16:45 +08005280 /**
5281 * {@hide}
5282 * Returns the IMS Registration Status on a particular subid
5283 *
5284 * @param subId
5285 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005286 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005287 Phone phone = getPhone(subId);
5288 if (phone != null) {
5289 return phone.isImsRegistered();
5290 } else {
5291 return false;
5292 }
5293 }
5294
Santos Cordon7a1885b2015-02-03 11:15:19 -08005295 @Override
5296 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005303 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005304
Tyler Gunnf70ed162019-04-03 15:28:53 -07005305 @Override
5306 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5307 final long identity = Binder.clearCallingIdentity();
5308 try {
5309 Phone phone = getPhone(subscriptionId);
5310 if (phone == null) {
5311 return null;
5312 }
5313 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005319 /**
5320 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005321 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005322 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 Phone phone = getPhone(subId);
5326 if (phone != null) {
5327 return phone.isWifiCallingEnabled();
5328 } else {
5329 return false;
5330 }
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005333 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005334 }
5335
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005336 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005337 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005338 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005339 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 Phone phone = getPhone(subId);
5343 if (phone != null) {
5344 return phone.isVideoEnabled();
5345 } else {
5346 return false;
5347 }
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005350 }
5351 }
5352
5353 /**
5354 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5355 * defined in {@link ImsRegistrationImplBase}.
5356 */
5357 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 Phone phone = getPhone(subId);
5361 if (phone != null) {
5362 return phone.getImsRegistrationTech();
5363 } else {
5364 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5365 }
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005368 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005369 }
5370
Stuart Scott8eef64f2015-04-08 15:13:54 -07005371 @Override
5372 public void factoryReset(int subId) {
5373 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005374 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5375 return;
5376 }
5377
Svet Ganovcc087f82015-05-12 20:35:54 -07005378 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005379
Svet Ganovcc087f82015-05-12 20:35:54 -07005380 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005381 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5382 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005383 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005384 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005385 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005386 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5387 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005388 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005389 // There has been issues when Sms raw table somehow stores orphan
5390 // fragments. They lead to garbled message when new fragments come
5391 // in and combined with those stale ones. In case this happens again,
5392 // user can reset all network settings which will clean up this table.
5393 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005396 }
5397 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005398
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005399 private void cleanUpSmsRawTable(Context context) {
5400 ContentResolver resolver = context.getContentResolver();
5401 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5402 resolver.delete(uri, null, null);
5403 }
5404
Narayan Kamath1c496c22015-04-16 14:40:19 +01005405 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005406 public String getSimLocaleForSubscriber(int subId) {
5407 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5408 final Phone phone = getPhone(subId);
5409 if (phone == null) {
5410 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005411 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
chen xu5d3637b2019-01-21 23:31:38 -08005415 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5416 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005417 if (info == null) {
5418 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5419 return null;
5420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 // Try and fetch the locale from the carrier properties or from the SIM language
5422 // preferences (EF-PL and EF-LI)...
5423 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005425 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5426 if (localeFromDefaultSim != null) {
5427 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5428 if (DBG) log("Using locale from subId: " + subId + " locale: "
5429 + localeFromDefaultSim);
5430 return localeFromDefaultSim.toLanguageTag();
5431 } else {
5432 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 }
5434 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 // The SIM language preferences only store a language (e.g. fr = French), not an
5437 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5438 // the SIM and carrier preferences does not include a country we add the country
5439 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005440 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005442 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 return mccLocale.toLanguageTag();
5444 }
5445
5446 if (DBG) log("No locale found - returning null");
5447 return null;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005451 }
5452
5453 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005454 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005455 }
5456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 /**
5458 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5459 */
5460 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005461 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005462 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005463
Chenjie Yu1ba97252018-01-11 18:16:20 -08005464 private final ModemActivityInfo mLastModemActivityInfo =
5465 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5466
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005467 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005468 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5469 * representing the state of the modem.
5470 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005471 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5472 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005473 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005474 */
5475 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005476 public void requestModemActivityInfo(ResultReceiver result) {
5477 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 ModemActivityInfo ret = null;
5483 synchronized (mLastModemActivityInfo) {
5484 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5485 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005486 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005487 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5489 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5491 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 }
5493 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005494 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5495 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 mLastModemActivityInfo.setIdleTimeMillis(
5497 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5498 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5499 mLastModemActivityInfo.setRxTimeMillis(
5500 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5501 mLastModemActivityInfo.setEnergyUsed(
5502 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5505 mLastModemActivityInfo.getSleepTimeMillis(),
5506 mLastModemActivityInfo.getIdleTimeMillis(),
5507 mLastModemActivityInfo.getTxTimeMillis(),
5508 mLastModemActivityInfo.getRxTimeMillis(),
5509 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 Bundle bundle = new Bundle();
5512 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5513 result.send(0, bundle);
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005516 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005517 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005518
Siddharth Rayb8114062018-06-17 15:02:38 -07005519 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5520 // less than total activity duration.
5521 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5522 if (info == null) {
5523 return false;
5524 }
5525 int activityDurationMs =
5526 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5527 int totalTxTimeMs = 0;
5528 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5529 totalTxTimeMs += info.getTxTimeMillis()[i];
5530 }
5531 return (info.isValid()
5532 && (info.getSleepTimeMillis() <= activityDurationMs)
5533 && (info.getIdleTimeMillis() <= activityDurationMs)
5534 && (info.getRxTimeMillis() <= activityDurationMs)
5535 && (totalTxTimeMs <= activityDurationMs));
5536 }
5537
Jack Yu85bd38a2015-11-09 11:34:32 -08005538 /**
5539 * {@hide}
5540 * Returns the service state information on specified subscription.
5541 */
5542 @Override
5543 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005545 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005546 return null;
5547 }
5548
Hall Liuf19c44f2018-11-27 14:38:17 -08005549 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5550 LocationAccessPolicy.checkLocationPermission(mApp,
5551 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5552 .setCallingPackage(callingPackage)
5553 .setCallingPid(Binder.getCallingPid())
5554 .setCallingUid(Binder.getCallingUid())
5555 .setMethod("getServiceStateForSubscriber")
5556 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5557 .build());
5558
5559 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5560 LocationAccessPolicy.checkLocationPermission(mApp,
5561 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5562 .setCallingPackage(callingPackage)
5563 .setCallingPid(Binder.getCallingPid())
5564 .setCallingUid(Binder.getCallingUid())
5565 .setMethod("getServiceStateForSubscriber")
5566 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5567 .build());
5568 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5569 boolean hasFinePermission =
5570 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5571 boolean hasCoarsePermission =
5572 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 final Phone phone = getPhone(subId);
5577 if (phone == null) {
5578 return null;
5579 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005580
Hall Liuf19c44f2018-11-27 14:38:17 -08005581 ServiceState ss = phone.getServiceState();
5582
5583 // Scrub out the location info in ServiceState depending on what level of access
5584 // the caller has.
5585 if (hasFinePermission) return ss;
5586 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5587 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005591 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005592
5593 /**
5594 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5595 *
5596 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5597 * voicemail ringtone.
5598 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5599 * PhoneAccount.
5600 */
5601 @Override
5602 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5606 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005607 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005614 }
5615
5616 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005617 * Sets the per-account voicemail ringtone.
5618 *
5619 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5620 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5621 *
5622 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5623 * voicemail ringtone.
5624 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5625 * PhoneAccount.
5626 */
5627 @Override
5628 public void setVoicemailRingtoneUri(String callingPackage,
5629 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005630 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5632 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005633 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5636 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638
5639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5642 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 }
5645 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005648 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005649 }
5650
5651 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005652 * Returns whether vibration is set for voicemail notification in Phone settings.
5653 *
5654 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5655 * voicemail vibration setting.
5656 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5657 */
5658 @Override
5659 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5663 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005664 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005671 }
5672
Youhan Wange64578a2016-05-02 15:32:42 -07005673 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005674 * Sets the per-account voicemail vibration.
5675 *
5676 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5677 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5678 *
5679 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5680 * voicemail vibration setting.
5681 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5682 * specific PhoneAccount.
5683 */
5684 @Override
5685 public void setVoicemailVibrationEnabled(String callingPackage,
5686 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005687 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5689 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005690 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5692 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5693 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005694 }
5695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5699 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005700 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 }
5702 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005705 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005706 }
5707
5708 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005709 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5710 *
5711 * @throws SecurityException if the caller does not have the required permission
5712 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005713 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005715 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005716 }
5717
5718 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005719 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5720 * permission.
5721 *
5722 * @throws SecurityException if the caller does not have the required permission
5723 */
5724 private void enforceSendSmsPermission() {
5725 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5726 }
5727
5728 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005729 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005730 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005731 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005732 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005733 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 if (componentName == null) {
5739 throw new SecurityException(
5740 "Caller not current active visual voicemail package[null]");
5741 }
5742 String vvmPackage = componentName.getPackageName();
5743 if (!callingPackage.equals(vvmPackage)) {
5744 throw new SecurityException("Caller not current active visual voicemail package["
5745 + vvmPackage + "]");
5746 }
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005749 }
5750 }
5751
5752 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005753 * Return the application ID for the app type.
5754 *
5755 * @param subId the subscription ID that this request applies to.
5756 * @param appType the uicc app type.
5757 * @return Application ID for specificied app type, or null if no uicc.
5758 */
5759 @Override
5760 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005761 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005762 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005765 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 if (phone == null) {
5767 return null;
5768 }
5769 String aid = null;
5770 try {
5771 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5772 .getApplicationByType(appType).getAid();
5773 } catch (Exception e) {
5774 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5775 }
5776 return aid;
5777 } finally {
5778 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005779 }
Youhan Wange64578a2016-05-02 15:32:42 -07005780 }
5781
Youhan Wang4001d252016-05-11 10:29:41 -07005782 /**
5783 * Return the Electronic Serial Number.
5784 *
5785 * @param subId the subscription ID that this request applies to.
5786 * @return ESN or null if error.
5787 */
5788 @Override
5789 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005790 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005791 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792
5793 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005794 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 if (phone == null) {
5796 return null;
5797 }
5798 String esn = null;
5799 try {
5800 esn = phone.getEsn();
5801 } catch (Exception e) {
5802 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5803 }
5804 return esn;
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005807 }
Youhan Wang4001d252016-05-11 10:29:41 -07005808 }
5809
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005810 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005811 * Return the Preferred Roaming List Version.
5812 *
5813 * @param subId the subscription ID that this request applies to.
5814 * @return PRLVersion or null if error.
5815 */
5816 @Override
5817 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005818 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005819 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820
5821 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005822 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 if (phone == null) {
5824 return null;
5825 }
5826 String cdmaPrlVersion = null;
5827 try {
5828 cdmaPrlVersion = phone.getCdmaPrlVersion();
5829 } catch (Exception e) {
5830 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5831 }
5832 return cdmaPrlVersion;
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005835 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005836 }
5837
5838 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005839 * Get snapshot of Telephony histograms
5840 * @return List of Telephony histograms
5841 * @hide
5842 */
5843 @Override
5844 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5846 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 return RIL.getTelephonyRILTimingHistograms();
5851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005854 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005855
5856 /**
5857 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005858 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5859 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005860 * Require system privileges. In the future we may add this to carrier APIs.
5861 *
Michele Berionne482f8202018-11-27 18:57:59 -08005862 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005863 */
5864 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005865 @TelephonyManager.SetCarrierRestrictionResult
5866 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005867 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005869
Michele Berionne482f8202018-11-27 18:57:59 -08005870 if (carrierRestrictionRules == null) {
5871 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005872 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005876 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005877 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 } finally {
5879 Binder.restoreCallingIdentity(identity);
5880 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005881 }
5882
5883 /**
5884 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005885 * Get the allowed carrier list and the excluded carrier list, including the priority between
5886 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005887 * Require system privileges. In the future we may add this to carrier APIs.
5888 *
Michele Berionne482f8202018-11-27 18:57:59 -08005889 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005890 */
5891 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005892 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005893 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005898 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5899 if (response instanceof CarrierRestrictionRules) {
5900 return (CarrierRestrictionRules) response;
5901 }
5902 // Response is an Exception of some kind,
5903 // which is signalled to the user as a NULL retval
5904 return null;
5905 } catch (Exception e) {
5906 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5907 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005911 }
5912
fionaxu59545b42016-05-25 15:53:37 -07005913 /**
5914 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5915 * @param subId the subscription ID that this action applies to.
5916 * @param enabled control enable or disable metered apns.
5917 * {@hide}
5918 */
5919 @Override
5920 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5921 enforceModifyPermission();
5922 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923
5924 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005925 if (phone == null) {
5926 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5927 return;
5928 }
5929 try {
5930 phone.carrierActionSetMeteredApnsEnabled(enabled);
5931 } catch (Exception e) {
5932 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 } finally {
5934 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005935 }
5936 }
5937
5938 /**
5939 * Action set from carrier signalling broadcast receivers to enable/disable radio
5940 * @param subId the subscription ID that this action applies to.
5941 * @param enabled control enable or disable radio.
5942 * {@hide}
5943 */
5944 @Override
5945 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5946 enforceModifyPermission();
5947 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948
5949 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005950 if (phone == null) {
5951 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5952 return;
5953 }
5954 try {
5955 phone.carrierActionSetRadioEnabled(enabled);
5956 } catch (Exception e) {
5957 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005960 }
5961 }
5962
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005963 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005964 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5965 * network status based on which carrier apps could apply actions accordingly,
5966 * enable/disable default url handler for example.
5967 *
5968 * @param subId the subscription ID that this action applies to.
5969 * @param report control start/stop reporting the default network status.
5970 * {@hide}
5971 */
5972 @Override
5973 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5974 enforceModifyPermission();
5975 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976
5977 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005978 if (phone == null) {
5979 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5980 return;
5981 }
5982 try {
5983 phone.carrierActionReportDefaultNetworkStatus(report);
5984 } catch (Exception e) {
5985 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 } finally {
5987 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005988 }
5989 }
5990
5991 /**
fionaxud9622282017-07-17 17:51:30 -07005992 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5993 * @param subId the subscription ID that this action applies to.
5994 * {@hide}
5995 */
5996 @Override
5997 public void carrierActionResetAll(int subId) {
5998 enforceModifyPermission();
5999 final Phone phone = getPhone(subId);
6000 if (phone == null) {
6001 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6002 return;
6003 }
6004 try {
6005 phone.carrierActionResetAll();
6006 } catch (Exception e) {
6007 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6008 }
6009 }
6010
6011 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006012 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6013 * bug report is being generated.
6014 */
6015 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006016 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6018 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006019 writer.println("Permission Denial: can't dump Phone from pid="
6020 + Binder.getCallingPid()
6021 + ", uid=" + Binder.getCallingUid()
6022 + "without permission "
6023 + android.Manifest.permission.DUMP);
6024 return;
6025 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006027 }
Jack Yueb89b242016-06-22 13:27:47 -07006028
Brad Ebingerdac2f002018-04-03 15:17:52 -07006029 @Override
6030 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6031 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6032 throws RemoteException {
6033 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6034 }
6035
Jack Yueb89b242016-06-22 13:27:47 -07006036 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006037 * Get aggregated video call data usage since boot.
6038 *
6039 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6040 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006041 * {@hide}
6042 */
6043 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006044 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006045 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6046 null);
6047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final long identity = Binder.clearCallingIdentity();
6049 try {
6050 // NetworkStatsService keeps tracking the active network interface and identity. It
6051 // records the delta with the corresponding network identity.
6052 // We just return the total video call data usage snapshot since boot.
6053 Phone phone = getPhone(subId);
6054 if (phone != null) {
6055 return phone.getVtDataUsage(perUidStats);
6056 }
6057 return null;
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006060 }
Jack Yueb89b242016-06-22 13:27:47 -07006061 }
Jack Yu75ab2952016-07-08 14:29:33 -07006062
6063 /**
6064 * Policy control of data connection. Usually used when data limit is passed.
6065 * @param enabled True if enabling the data, otherwise disabling.
6066 * @param subId Subscription index
6067 * {@hide}
6068 */
6069 @Override
6070 public void setPolicyDataEnabled(boolean enabled, int subId) {
6071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072
6073 final long identity = Binder.clearCallingIdentity();
6074 try {
6075 Phone phone = getPhone(subId);
6076 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006077 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 }
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006081 }
6082 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006083
6084 /**
6085 * Get Client request stats
6086 * @return List of Client Request Stats
6087 * @hide
6088 */
6089 @Override
6090 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006092 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006093 return null;
6094 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006095 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
6098 try {
6099 if (phone != null) {
6100 return phone.getClientRequestStats();
6101 }
6102
6103 return null;
6104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006107 }
6108
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006109 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006110 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006111 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006112 }
Jack Yueb4124c2017-02-16 15:32:43 -08006113
6114 /**
Grace Chen70990072017-03-24 17:21:30 -07006115 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006116 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006117 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006118 * @param state State of SIM (power down, power up, pass through)
6119 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6120 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6121 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006122 *
6123 **/
6124 @Override
Grace Chen70990072017-03-24 17:21:30 -07006125 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006126 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006127 Phone phone = PhoneFactory.getPhone(slotIndex);
6128
vagdeviaf9a5b92018-08-15 16:01:53 -07006129 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006134 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 }
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006138 }
6139 }
Shuo Qiandd210312017-04-12 22:11:33 +00006140
Tyler Gunn65d45c22017-06-05 11:22:26 -07006141 private boolean isUssdApiAllowed(int subId) {
6142 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006143 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006144 if (configManager == null) {
6145 return false;
6146 }
6147 PersistableBundle pb = configManager.getConfigForSubId(subId);
6148 if (pb == null) {
6149 return false;
6150 }
6151 return pb.getBoolean(
6152 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6153 }
6154
Shuo Qiandd210312017-04-12 22:11:33 +00006155 /**
6156 * Check if phone is in emergency callback mode
6157 * @return true if phone is in emergency callback mode
6158 * @param subId sub id
6159 */
goneil9c5f4872017-12-05 14:07:56 -08006160 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006161 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006162 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006163 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164
6165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 if (phone != null) {
6168 return phone.isInEcm();
6169 } else {
6170 return false;
6171 }
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006174 }
6175 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006176
6177 /**
6178 * Get the current signal strength information for the given subscription.
6179 * Because this information is not updated when the device is in a low power state
6180 * it should not be relied-upon to be current.
6181 * @param subId Subscription index
6182 * @return the most recent cached signal strength info from the modem
6183 */
6184 @Override
6185 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 Phone p = getPhone(subId);
6189 if (p == null) {
6190 return null;
6191 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 return p.getSignalStrength();
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006197 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006198
Pengquan Meng77b7f132018-08-22 14:49:57 -07006199 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006200 * Get the current modem radio state for the given slot.
6201 * @param slotIndex slot index.
6202 * @param callingPackage the name of the package making the call.
6203 * @return the current radio power state from the modem
6204 */
6205 @Override
6206 public int getRadioPowerState(int slotIndex, String callingPackage) {
6207 Phone phone = PhoneFactory.getPhone(slotIndex);
6208 if (phone != null) {
6209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6210 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6211 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6212 }
6213
6214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 return phone.getRadioPowerState();
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
6219 }
6220 }
6221 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6222 }
6223
6224 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006225 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6226 *
6227 * <p>Requires one of the following permissions:
6228 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6229 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6230 * privileges.
6231 *
6232 * @param subId subscription id
6233 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6234 * {@code false}.
6235 */
6236 @Override
6237 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006238 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6239 null /* message */);
6240
Pengquan Menga1bb6272018-09-06 09:59:22 -07006241 boolean isEnabled = false;
6242 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006243 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006244 Phone phone = getPhone(subId);
6245 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006246 } catch (Exception e) {
6247 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6248 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006251 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006252 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006253 }
6254
6255
6256 /**
6257 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6258 *
6259 * <p> Requires permission:
6260 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6261 * privileges.
6262 *
6263 * @param subId subscription id
6264 * @param isEnabled {@code true} means enable, {@code false} means disable.
6265 */
6266 @Override
6267 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6269 mApp, subId, "setDataRoamingEnabled");
6270
Pengquan Menga1bb6272018-09-06 09:59:22 -07006271 final long identity = Binder.clearCallingIdentity();
6272 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006273 Phone phone = getPhone(subId);
6274 if (phone != null) {
6275 phone.setDataRoamingEnabled(isEnabled);
6276 }
6277 } finally {
6278 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006279 }
6280 }
6281
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006282 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006283 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006284 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6285 mApp, subId, "isManualNetworkSelectionAllowed");
6286
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006287 boolean isAllowed = true;
6288 final long identity = Binder.clearCallingIdentity();
6289 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006290 Phone phone = getPhone(subId);
6291 if (phone != null) {
6292 isAllowed = phone.isCspPlmnEnabled();
6293 }
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
6297 return isAllowed;
6298 }
6299
6300 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006301 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liuc65bc952019-02-12 17:54:02 -08006302 try {
6303 enforceReadPrivilegedPermission("getUiccCardsInfo");
6304 } catch (SecurityException e) {
6305 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6306 // has carrier privileges on an active UICC
6307 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6308 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6309 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6310 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006311 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006312
6313 final long identity = Binder.clearCallingIdentity();
6314 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006315 UiccController uiccController = UiccController.getInstance();
6316 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6317
6318 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6319 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6320 // Remove private info if the caller doesn't have access
6321 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6322 for (UiccCardInfo cardInfo : cardInfos) {
6323 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6324 UiccProfile profile = card.getUiccProfile();
6325 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6326 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6327 filteredInfos.add(cardInfo.getUnprivileged());
6328 } else {
6329 filteredInfos.add(cardInfo);
6330 }
6331 }
6332 return filteredInfos;
6333 }
6334 return cardInfos;
6335 } catch (PackageManager.NameNotFoundException e) {
6336 // This should not happen since we pass the package info in from TelephonyManager
6337 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
6341 }
6342
6343 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006344 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006345 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6350 if (slots == null) {
6351 Rlog.i(LOG_TAG, "slots is null.");
6352 return null;
6353 }
6354
6355 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6356 for (int i = 0; i < slots.length; i++) {
6357 UiccSlot slot = slots[i];
6358 if (slot == null) {
6359 continue;
6360 }
6361
6362 String cardId;
6363 UiccCard card = slot.getUiccCard();
6364 if (card != null) {
6365 cardId = card.getCardId();
6366 } else {
6367 cardId = slot.getIccId();
6368 }
6369
6370 int cardState = 0;
6371 switch (slot.getCardState()) {
6372 case CARDSTATE_ABSENT:
6373 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6374 break;
6375 case CARDSTATE_PRESENT:
6376 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6377 break;
6378 case CARDSTATE_ERROR:
6379 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6380 break;
6381 case CARDSTATE_RESTRICTED:
6382 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6383 break;
6384 default:
6385 break;
6386
6387 }
6388
6389 infos[i] = new UiccSlotInfo(
6390 slot.isActive(),
6391 slot.isEuicc(),
6392 cardId,
6393 cardState,
6394 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006395 slot.isExtendedApduSupported(),
6396 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 }
6398 return infos;
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006401 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006402 }
6403
6404 @Override
6405 public boolean switchSlots(int[] physicalSlots) {
6406 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006414 }
Jack Yu4c988042018-02-27 15:30:01 -08006415
6416 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006417 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006418 final long identity = Binder.clearCallingIdentity();
6419 try {
6420 return UiccController.getInstance().getCardIdForDefaultEuicc();
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
6424 }
6425
6426 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006427 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6428 enforceModifyPermission();
6429 final Phone phone = getPhone(subId);
6430 if (phone == null) {
6431 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6432 return;
6433 }
6434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 final long identity = Binder.clearCallingIdentity();
6436 try {
6437 phone.setRadioIndicationUpdateMode(filters, mode);
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
Jack Yu4c988042018-02-27 15:30:01 -08006441 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006442
6443 /**
goneil47ffb6e2018-04-06 15:40:58 -07006444 * A test API to reload the UICC profile.
6445 *
6446 * <p>Requires that the calling app has permission
6447 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6448 * @hide
6449 */
6450 @Override
6451 public void refreshUiccProfile(int subId) {
6452 enforceModifyPermission();
6453
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 Phone phone = getPhone(subId);
6457 if (phone == null) {
6458 return;
6459 }
6460 UiccCard uiccCard = phone.getUiccCard();
6461 if (uiccCard == null) {
6462 return;
6463 }
6464 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6465 if (uiccProfile == null) {
6466 return;
6467 }
6468 uiccProfile.refresh();
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
6472 }
6473
6474 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006475 * Returns false if the mobile data is disabled by default, otherwise return true.
6476 */
6477 private boolean getDefaultDataEnabled() {
6478 return "true".equalsIgnoreCase(
6479 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6480 }
6481
6482 /**
6483 * Returns true if the data roaming is enabled by default, i.e the system property
6484 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6485 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6486 */
6487 private boolean getDefaultDataRoamingEnabled(int subId) {
6488 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006489 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006490 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6491 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6492 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6493 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6494 return isDataRoamingEnabled;
6495 }
6496
6497 /**
6498 * Returns the default network type for the given {@code subId}, if the default network type is
6499 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6500 */
6501 private int getDefaultNetworkType(int subId) {
6502 return Integer.parseInt(
6503 TelephonyManager.getTelephonyProperty(
6504 mSubscriptionController.getPhoneId(subId),
6505 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6506 String.valueOf(Phone.PREFERRED_NT_MODE)));
6507 }
fionaxua13278b2018-03-21 00:08:13 -07006508
6509 @Override
6510 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006511 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 final Phone phone = getPhone(subId);
6517 if (phone == null) {
6518 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6519 return;
6520 }
chen xueaba88a2019-03-15 13:15:10 -07006521 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6522 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 } finally {
6524 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006525 }
fionaxua13278b2018-03-21 00:08:13 -07006526 }
6527
6528 @Override
6529 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006530 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 final Phone phone = getPhone(subId);
6535 if (phone == null) {
6536 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6537 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6538 }
6539 return phone.getCarrierIdListVersion();
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006542 }
fionaxua13278b2018-03-21 00:08:13 -07006543 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006544
6545 @Override
6546 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6548 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6549 return -1;
6550 }
6551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6555 } finally {
6556 Binder.restoreCallingIdentity(identity);
6557 }
6558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006559
6560 @Override
6561 public int getCdmaRoamingMode(int subId) {
6562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6563 mApp, subId, "getCdmaRoamingMode");
6564
6565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
6571 }
6572
6573 @Override
6574 public boolean setCdmaRoamingMode(int subId, int mode) {
6575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6576 mApp, subId, "setCdmaRoamingMode");
6577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
6584 }
6585
6586 @Override
6587 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6589 mApp, subId, "setCdmaSubscriptionMode");
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006598
6599 private void ensureUserRunning(int userId) {
6600 if (!mUserManager.isUserRunning(userId)) {
6601 throw new IllegalStateException("User " + userId + " does not exist or not running");
6602 }
6603 }
6604
6605 /**
6606 * Returns a list of SMS apps on a given user.
6607 *
6608 * Only the shell user (UID 2000 or 0) can call it.
6609 * Target user must be running.
6610 */
6611 @Override
6612 public String[] getSmsApps(int userId) {
6613 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6614 ensureUserRunning(userId);
6615
6616 final Collection<SmsApplicationData> apps =
6617 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6618
6619 String[] ret = new String[apps.size()];
6620 int i = 0;
6621 for (SmsApplicationData app : apps) {
6622 ret[i++] = app.mPackageName;
6623 }
6624 return ret;
6625 }
6626
6627 /**
6628 * Returns the default SMS app package name on a given user.
6629 *
6630 * Only the shell user (UID 2000 or 0) can call it.
6631 * Target user must be running.
6632 */
6633 @Override
6634 public String getDefaultSmsApp(int userId) {
6635 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6636 ensureUserRunning(userId);
6637
6638 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6639 /* updateIfNeeded= */ true, userId);
6640 return cn == null ? null : cn.getPackageName();
6641 }
6642
6643 /**
6644 * Set a package as the default SMS app on a given user.
6645 *
6646 * Only the shell user (UID 2000 or 0) can call it.
6647 * Target user must be running.
6648 */
6649 @Override
6650 public void setDefaultSmsApp(int userId, String packageName) {
6651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6652 ensureUserRunning(userId);
6653
6654 boolean found = false;
6655 for (String pkg : getSmsApps(userId)) {
6656 if (TextUtils.equals(packageName, pkg)) {
6657 found = true;
6658 break;
6659 }
6660 }
6661 if (!found) {
6662 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6663 }
6664
6665 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6666 }
sqianc5eccab2018-10-19 18:46:41 -07006667
6668 @Override
sqian8c685422019-02-22 15:55:18 -08006669 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006670 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006672 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006673 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6674 }
6675 final long identity = Binder.clearCallingIdentity();
6676 try {
sqian854d44b2018-12-12 16:48:18 -08006677 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6678 for (Phone phone: PhoneFactory.getPhones()) {
6679 if (phone.getEmergencyNumberTracker() != null
6680 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6681 emergencyNumberListInternal.put(
6682 phone.getSubId(),
6683 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6684 }
sqian11b7a0e2018-12-05 18:48:28 -08006685 }
sqian854d44b2018-12-12 16:48:18 -08006686 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006687 } finally {
6688 Binder.restoreCallingIdentity(identity);
6689 }
sqianc5eccab2018-10-19 18:46:41 -07006690 }
6691
6692 @Override
sqian8c685422019-02-22 15:55:18 -08006693 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006694 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006695 if (!exactMatch) {
6696 TelephonyPermissions
6697 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006698 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006699 }
6700 final long identity = Binder.clearCallingIdentity();
6701 try {
sqian854d44b2018-12-12 16:48:18 -08006702 for (Phone phone: PhoneFactory.getPhones()) {
6703 if (phone.getEmergencyNumberTracker() != null
6704 && phone.getEmergencyNumberTracker() != null) {
6705 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6706 number, exactMatch)) {
6707 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006708 }
6709 }
sqian11b7a0e2018-12-05 18:48:28 -08006710 }
6711 return false;
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
6715 }
6716
sqianf4ca7ed2019-01-15 18:32:07 -08006717 /**
6718 * Update emergency number list for test mode.
6719 */
6720 @Override
6721 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6723 "updateEmergencyNumberListTestMode");
6724
6725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 for (Phone phone: PhoneFactory.getPhones()) {
6728 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6729 if (tracker != null) {
6730 tracker.executeEmergencyNumberTestModeCommand(action, num);
6731 }
6732 }
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
6736 }
6737
6738 /**
6739 * Get the full emergency number list for test mode.
6740 */
6741 @Override
6742 public List<String> getEmergencyNumberListTestMode() {
6743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6744 "getEmergencyNumberListTestMode");
6745
6746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 Set<String> emergencyNumbers = new HashSet<>();
6749 for (Phone phone: PhoneFactory.getPhones()) {
6750 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6751 if (tracker != null) {
6752 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6753 emergencyNumbers.add(num.getNumber());
6754 }
6755 }
6756 }
6757 return new ArrayList<>(emergencyNumbers);
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 }
6762
chen xud6b45bd2018-10-30 22:27:10 -07006763 @Override
6764 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6765 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6766 Phone phone = getPhone(subId);
6767 if (phone == null) {
6768 return null;
6769 }
6770 final long identity = Binder.clearCallingIdentity();
6771 try {
6772 UiccProfile profile = UiccController.getInstance()
6773 .getUiccProfileForPhone(phone.getPhoneId());
6774 if (profile != null) {
6775 return profile.getCertsFromCarrierPrivilegeAccessRules();
6776 }
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
6779 }
6780 return null;
6781 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006782
6783 /**
6784 * Enable or disable a modem stack.
6785 */
6786 @Override
6787 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6788 enforceModifyPermission();
6789
6790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 Phone phone = PhoneFactory.getPhone(slotIndex);
6793 if (phone == null) {
6794 return false;
6795 } else {
6796 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6797 }
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
6801 }
Michelecea4cf22018-12-21 15:00:11 -08006802
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006803 /**
6804 * Whether a modem stack is enabled or not.
6805 */
6806 @Override
6807 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6808 Phone phone = PhoneFactory.getPhone(slotIndex);
6809 if (phone == null) return false;
6810
6811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6812 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6813 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6814 }
6815
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 return PhoneConfigurationManager.getInstance().getPhoneStatus(phone);
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 }
6823
Michelecea4cf22018-12-21 15:00:11 -08006824 @Override
Michele0ea7d782019-03-19 14:58:42 -07006825 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006826 enforceModifyPermission();
6827
6828 final long identity = Binder.clearCallingIdentity();
6829 try {
6830 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006831 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006832 .commit();
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
6835 }
6836 }
6837
6838 @Override
Michele0ea7d782019-03-19 14:58:42 -07006839 @TelephonyManager.IsMultiSimSupportedResult
6840 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006842 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6843 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006844 }
Michelecea4cf22018-12-21 15:00:11 -08006845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
Michele0ea7d782019-03-19 14:58:42 -07006848 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006849 } finally {
6850 Binder.restoreCallingIdentity(identity);
6851 }
6852 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006853
Michele0ea7d782019-03-19 14:58:42 -07006854 @TelephonyManager.IsMultiSimSupportedResult
6855 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006856 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6857 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6858 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006859 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6860 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006861 }
6862 // Check if the hardware supports multisim functionality. If usage of multisim is not
6863 // supported by the modem, indicate that it is restricted.
6864 PhoneCapability staticCapability =
6865 mPhoneConfigurationManager.getStaticPhoneCapability();
6866 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006867 loge("isMultiSimSupportedInternal: no static configuration available");
6868 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006869 }
6870 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006871 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6872 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006873 }
6874 // Check if support of multiple SIMs is restricted by carrier
6875 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006876 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006877 }
6878
Michele0ea7d782019-03-19 14:58:42 -07006879 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006880 }
6881
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006882 /**
6883 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006884 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6885 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6886 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006887 * @param numOfSims number of active sims we want to switch to
6888 */
6889 @Override
6890 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006891 if (numOfSims == 1) {
6892 enforceModifyPermission();
6893 } else {
6894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6895 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6896 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006897 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006898
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006899 try {
Michele30b57b22019-03-01 12:01:14 -08006900 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006901 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006902 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6903 return;
6904 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006905 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6906 } finally {
6907 Binder.restoreCallingIdentity(identity);
6908 }
6909 }
6910
6911 /**
chen xub4baa772019-04-03 10:23:41 -07006912 * Get whether making changes to modem configurations will trigger reboot.
6913 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006914 */
6915 @Override
chen xub4baa772019-04-03 10:23:41 -07006916 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6918 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6919 return false;
6920 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 }
6928
Nathan Harold29f5f052019-02-15 13:41:57 -08006929 private void updateModemStateMetrics() {
6930 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6931 // TODO: check the state for each modem if the api is ready.
6932 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6933 }
6934
Pengquan Meng3889a572019-01-23 11:16:29 -08006935 @Override
6936 public int[] getSlotsMapping() {
6937 enforceReadPrivilegedPermission("getSlotsMapping");
6938
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6942 // All logical slots should have a mapping to a physical slot.
6943 int[] logicalSlotsMapping = new int[phoneCount];
6944 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6945 for (int i = 0; i < slotInfos.length; i++) {
6946 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6947 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6948 }
6949 }
6950 return logicalSlotsMapping;
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
6954 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006955
6956 /**
6957 * Get the IRadio HAL Version
6958 */
6959 @Override
6960 public int getRadioHalVersion() {
6961 Phone phone = getDefaultPhone();
6962 if (phone == null) return -1;
6963 HalVersion hv = phone.getHalVersion();
6964 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6965 return hv.major * 100 + hv.minor;
6966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006967}