blob: 494b89b7e6ff91531f5d77e9f2c2713ef72513b6 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080089import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080091import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070092import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsMmTelFeature;
94import android.telephony.ims.aidl.IImsRcsFeature;
95import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.feature.MmTelFeature;
98import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080099import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800103import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800105
Brad Ebinger4c460712018-10-01 10:40:55 -0700106import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700107import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800108import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700110import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700111import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800112import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700113import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700114import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800116import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800118import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100120import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700121import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700124import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800125import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700126import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700127import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700128import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700129import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700130import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700131import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800132import com.android.internal.telephony.SmsApplication;
133import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800134import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800135import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800136import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700137import com.android.internal.telephony.euicc.EuiccConnector;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800138import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.IccIoResult;
140import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800141import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700142import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800143import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800145import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000146import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700147import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800148import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700149import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800150import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700151import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700152import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800153
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700154import java.io.FileDescriptor;
155import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800156import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800159import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800160import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800161import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800162import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100163import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800164import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800165import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166
167/**
168 * Implementation of the ITelephony interface.
169 */
Santos Cordon117fee72014-05-16 17:56:12 -0700170public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171 private static final String LOG_TAG = "PhoneInterfaceManager";
172 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
173 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175
176 // Message codes used with mMainThreadHandler
177 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700178 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
179 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180 private static final int CMD_OPEN_CHANNEL = 9;
181 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
182 private static final int CMD_CLOSE_CHANNEL = 11;
183 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800184 private static final int CMD_NV_READ_ITEM = 13;
185 private static final int EVENT_NV_READ_ITEM_DONE = 14;
186 private static final int CMD_NV_WRITE_ITEM = 15;
187 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
188 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
189 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700190 private static final int CMD_RESET_MODEM_CONFIG = 19;
191 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800192 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
193 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
194 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
195 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800196 private static final int CMD_SEND_ENVELOPE = 25;
197 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000198 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
199 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700200 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
201 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
202 private static final int CMD_EXCHANGE_SIM_IO = 31;
203 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800204 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
205 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700206 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
207 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700208 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
209 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700210 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
211 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
212 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
213 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700214 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
215 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
216 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
217 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700218 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800219 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
220 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000221 private static final int CMD_SWITCH_SLOTS = 50;
222 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700223 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
224 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
225 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
226 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
227 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
228 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
229 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
230 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700231 private static final int CMD_GET_ALL_CELL_INFO = 60;
232 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
233 private static final int CMD_GET_CELL_LOCATION = 62;
234 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700235 private static final int CMD_MODEM_REBOOT = 64;
236 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700237 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
238 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800239 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
240 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800242 // Parameters of select command.
243 private static final int SELECT_COMMAND = 0xA4;
244 private static final int SELECT_P1 = 0x04;
245 private static final int SELECT_P2 = 0;
246 private static final int SELECT_P3 = 0x10;
247
Pengquan Meng85728fb2018-03-12 16:31:21 -0700248 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
249 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
250 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
251
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 /** The singleton instance. */
253 private static PhoneInterfaceManager sInstance;
254
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800256 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700257 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800258 private AppOpsManager mAppOps;
259 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800260 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800261 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700262 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263
Derek Tan97ebb422014-09-05 16:55:38 -0700264 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
265 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800266 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800267 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700268
Micheled3107c52018-12-21 15:00:11 -0800269 // String to store multi SIM allowed
270 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
271
Derek Tan740e1672017-06-27 14:56:27 -0700272 // The AID of ISD-R.
273 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
274
yinxub1bed742017-04-17 11:45:04 -0700275 private NetworkScanRequestTracker mNetworkScanRequestTracker;
276
David Kelly5e06a7f2018-03-12 14:10:59 +0000277 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
278 private static final int MANUFACTURER_CODE_LENGTH = 8;
279
Derek Tan89e89d42014-07-08 17:00:10 -0700280 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700281 * A request object to use for transmitting data to an ICC.
282 */
283 private static final class IccAPDUArgument {
284 public int channel, cla, command, p1, p2, p3;
285 public String data;
286
287 public IccAPDUArgument(int channel, int cla, int command,
288 int p1, int p2, int p3, String data) {
289 this.channel = channel;
290 this.cla = cla;
291 this.command = command;
292 this.p1 = p1;
293 this.p2 = p2;
294 this.p3 = p3;
295 this.data = data;
296 }
297 }
298
299 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700300 * A request object to use for transmitting data to an ICC.
301 */
302 private static final class ManualNetworkSelectionArgument {
303 public OperatorInfo operatorInfo;
304 public boolean persistSelection;
305
306 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
307 this.operatorInfo = operatorInfo;
308 this.persistSelection = persistSelection;
309 }
310 }
311
312 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
314 * request after sending. The main thread will notify the request when it is complete.
315 */
316 private static final class MainThreadRequest {
317 /** The argument to use for the request */
318 public Object argument;
319 /** The result of the request that is run on the main thread */
320 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800321 // The subscriber id that this request applies to. Defaults to
322 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
323 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324
Nathan Harold92bed182018-10-12 18:16:49 -0700325 // In cases where subId is unavailable, the caller needs to specify the phone.
326 public Phone phone;
327
vagdevie435a3e2018-08-15 16:01:53 -0700328 public WorkSource workSource;
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 public MainThreadRequest(Object argument) {
331 this.argument = argument;
332 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800333
Nathan Harold92bed182018-10-12 18:16:49 -0700334 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
335 this.argument = argument;
336 if (phone != null) {
337 this.phone = phone;
338 }
339 this.workSource = workSource;
340 }
341
vagdevie435a3e2018-08-15 16:01:53 -0700342 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800343 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800344 if (subId != null) {
345 this.subId = subId;
346 }
vagdevie435a3e2018-08-15 16:01:53 -0700347 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 }
350
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800351 private static final class IncomingThirdPartyCallArgs {
352 public final ComponentName component;
353 public final String callId;
354 public final String callerDisplayName;
355
356 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
357 String callerDisplayName) {
358 this.component = component;
359 this.callId = callId;
360 this.callerDisplayName = callerDisplayName;
361 }
362 }
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 /**
365 * A handler that processes messages on the main thread in the phone process. Since many
366 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
367 * inbound binder threads to the main thread in the phone process. The Binder thread
368 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
369 * on, which will be notified when the operation completes and will contain the result of the
370 * request.
371 *
372 * <p>If a MainThreadRequest object is provided in the msg.obj field,
373 * note that request.result must be set to something non-null for the calling thread to
374 * unblock.
375 */
376 private final class MainThreadHandler extends Handler {
377 @Override
378 public void handleMessage(Message msg) {
379 MainThreadRequest request;
380 Message onCompleted;
381 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800382 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700383 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800384 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
386 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700387 case CMD_HANDLE_USSD_REQUEST: {
388 request = (MainThreadRequest) msg.obj;
389 final Phone phone = getPhoneFromRequest(request);
390 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
391 String ussdRequest = ussdObject.first;
392 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Meng0c05b502018-09-06 09:59:22 -0700394 if (!isUssdApiAllowed(request.subId)) {
395 // Carrier does not support use of this API, return failure.
396 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
397 UssdResponse response = new UssdResponse(ussdRequest, null);
398 Bundle returnData = new Bundle();
399 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
400 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700401
Pengquan Meng0c05b502018-09-06 09:59:22 -0700402 request.result = true;
403 notifyRequester(request);
404 return;
405 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700406
Pengquan Meng0c05b502018-09-06 09:59:22 -0700407 try {
408 request.result = phone != null
409 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
410 } catch (CallStateException cse) {
411 request.result = false;
412 }
413 // Wake up the requesting thread
414 notifyRequester(request);
415 break;
pkanwar32d516d2016-10-14 19:37:38 -0700416 }
417
Yorke Lee716f67e2015-06-17 15:39:16 -0700418 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700420 final Phone phone = getPhoneFromRequest(request);
421 request.result = phone != null ?
422 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
423 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700425 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800432 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700433 if (uiccCard == null) {
434 loge("iccTransmitApduLogicalChannel: No UICC");
435 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700436 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700437 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
439 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 iccArgument.channel, iccArgument.cla, iccArgument.command,
442 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 break;
446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 ar = (AsyncResult) msg.obj;
449 request = (MainThreadRequest) ar.userObj;
450 if (ar.exception == null && ar.result != null) {
451 request.result = ar.result;
452 } else {
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
454 if (ar.result == null) {
455 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800456 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800458 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 } else {
460 loge("iccTransmitApduLogicalChannel: Unknown exception");
461 }
462 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700463 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 break;
465
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
467 request = (MainThreadRequest) msg.obj;
468 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800469 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 if (uiccCard == null) {
471 loge("iccTransmitApduBasicChannel: No UICC");
472 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700473 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 } else {
475 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
476 request);
477 uiccCard.iccTransmitApduBasicChannel(
478 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
479 iccArgument.p3, iccArgument.data, onCompleted);
480 }
481 break;
482
483 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
484 ar = (AsyncResult) msg.obj;
485 request = (MainThreadRequest) ar.userObj;
486 if (ar.exception == null && ar.result != null) {
487 request.result = ar.result;
488 } else {
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 if (ar.result == null) {
491 loge("iccTransmitApduBasicChannel: Empty response");
492 } else if (ar.exception instanceof CommandException) {
493 loge("iccTransmitApduBasicChannel: CommandException: " +
494 ar.exception);
495 } else {
496 loge("iccTransmitApduBasicChannel: Unknown exception");
497 }
498 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 break;
501
502 case CMD_EXCHANGE_SIM_IO:
503 request = (MainThreadRequest) msg.obj;
504 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800505 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 if (uiccCard == null) {
507 loge("iccExchangeSimIO: No UICC");
508 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 } else {
511 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
512 request);
513 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
514 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
515 iccArgument.data, onCompleted);
516 }
517 break;
518
519 case EVENT_EXCHANGE_SIM_IO_DONE:
520 ar = (AsyncResult) msg.obj;
521 request = (MainThreadRequest) ar.userObj;
522 if (ar.exception == null && ar.result != null) {
523 request.result = ar.result;
524 } else {
525 request.result = new IccIoResult(0x6f, 0, (byte[])null);
526 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 break;
529
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 case CMD_SEND_ENVELOPE:
531 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800532 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 if (uiccCard == null) {
534 loge("sendEnvelopeWithStatus: No UICC");
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 } else {
538 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
539 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
540 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 break;
542
543 case EVENT_SEND_ENVELOPE_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("sendEnvelopeWithStatus: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("sendEnvelopeWithStatus: CommandException: " +
554 ar.exception);
555 } else {
556 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700559 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 break;
561
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 case CMD_OPEN_CHANNEL:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800565 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800568 request.result = new IccOpenLogicalChannelResponse(-1,
569 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 } else {
572 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800573 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
574 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 break;
577
578 case EVENT_OPEN_CHANNEL_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 int[] result = (int[]) ar.result;
584 int channelId = result[0];
585 byte[] selectResponse = null;
586 if (result.length > 1) {
587 selectResponse = new byte[result.length - 1];
588 for (int i = 1; i < result.length; ++i) {
589 selectResponse[i - 1] = (byte) result[i];
590 }
591 }
592 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.result == null) {
596 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 if (ar.exception != null) {
599 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
600 }
601
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700603 if (ar.exception instanceof CommandException) {
604 CommandException.Error error =
605 ((CommandException) (ar.exception)).getCommandError();
606 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700607 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700608 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(
613 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700615 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 break;
618
619 case CMD_CLOSE_CHANNEL:
620 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 if (uiccCard == null) {
623 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900624 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 } else {
627 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
628 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
629 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 break;
631
632 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800633 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
634 break;
635
636 case CMD_NV_READ_ITEM:
637 request = (MainThreadRequest) msg.obj;
638 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800639 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
640 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800641 break;
642
643 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800649 request.result = "";
650 if (ar.result == null) {
651 loge("nvReadItem: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("nvReadItem: CommandException: " +
654 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800656 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
658 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700659 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
Jake Hambye994d462014-02-03 13:10:13 -0800662 case CMD_NV_WRITE_ITEM:
663 request = (MainThreadRequest) msg.obj;
664 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
665 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800666 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700667 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800668 break;
669
670 case EVENT_NV_WRITE_ITEM_DONE:
671 handleNullReturnEvent(msg, "nvWriteItem");
672 break;
673
674 case CMD_NV_WRITE_CDMA_PRL:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800677 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800678 break;
679
680 case EVENT_NV_WRITE_CDMA_PRL_DONE:
681 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
682 break;
683
chen xu1cc0abe2018-10-26 17:39:23 -0700684 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800685 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700686 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800687 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
chen xu1cc0abe2018-10-26 17:39:23 -0700690 case EVENT_RESET_MODEM_CONFIG_DONE:
691 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 case CMD_GET_PREFERRED_NETWORK_TYPE:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700697 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 break;
699
700 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result; // Integer
705 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800706 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 if (ar.result == null) {
708 loge("getPreferredNetworkType: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("getPreferredNetworkType: CommandException: " +
711 ar.exception);
712 } else {
713 loge("getPreferredNetworkType: Unknown exception");
714 }
715 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700716 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case CMD_SET_PREFERRED_NETWORK_TYPE:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
722 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700723 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 break;
725
726 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
727 handleNullReturnEvent(msg, "setPreferredNetworkType");
728 break;
729
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000730 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
731 request = (MainThreadRequest)msg.obj;
732 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800733 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000734 break;
735
736 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
737 ar = (AsyncResult)msg.obj;
738 request = (MainThreadRequest)ar.userObj;
739 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700740 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000741 break;
742
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800743 case CMD_SET_VOICEMAIL_NUMBER:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
746 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800747 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
748 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800749 break;
750
751 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
752 handleNullReturnEvent(msg, "setVoicemailNumber");
753 break;
754
Stuart Scott54788802015-03-30 13:18:01 -0700755 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
758 request);
759 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
760 break;
761
762 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
763 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
764 break;
765
Shishir Agrawal302c8692015-06-19 13:49:39 -0700766 case CMD_PERFORM_NETWORK_SCAN:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
769 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
770 break;
771
772 case EVENT_PERFORM_NETWORK_SCAN_DONE:
773 ar = (AsyncResult) msg.obj;
774 request = (MainThreadRequest) ar.userObj;
775 CellNetworkScanResult cellScanResult;
776 if (ar.exception == null && ar.result != null) {
777 cellScanResult = new CellNetworkScanResult(
778 CellNetworkScanResult.STATUS_SUCCESS,
779 (List<OperatorInfo>) ar.result);
780 } else {
781 if (ar.result == null) {
782 loge("getCellNetworkScanResults: Empty response");
783 }
784 if (ar.exception != null) {
785 loge("getCellNetworkScanResults: Exception: " + ar.exception);
786 }
787 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
788 if (ar.exception instanceof CommandException) {
789 CommandException.Error error =
790 ((CommandException) (ar.exception)).getCommandError();
791 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
792 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
793 } else if (error == CommandException.Error.GENERIC_FAILURE) {
794 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
795 }
796 }
797 cellScanResult = new CellNetworkScanResult(errorCode, null);
798 }
799 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700800 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 break;
802
803 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
804 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700805 ManualNetworkSelectionArgument selArg =
806 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
808 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700809 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
810 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
813 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700814 ar = (AsyncResult) msg.obj;
815 request = (MainThreadRequest) ar.userObj;
816 if (ar.exception == null) {
817 request.result = true;
818 } else {
819 request.result = false;
820 loge("setNetworkSelectionModeManual " + ar.exception);
821 }
822 notifyRequester(request);
823 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700826 case CMD_GET_MODEM_ACTIVITY_INFO:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800829 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700830 break;
831
832 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 if (ar.exception == null && ar.result != null) {
836 request.result = ar.result;
837 } else {
838 if (ar.result == null) {
839 loge("queryModemActivityInfo: Empty response");
840 } else if (ar.exception instanceof CommandException) {
841 loge("queryModemActivityInfo: CommandException: " +
842 ar.exception);
843 } else {
844 loge("queryModemActivityInfo: Unknown exception");
845 }
846 }
Amit Mahajand4766222016-01-28 15:28:28 -0800847 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
848 if (request.result == null) {
849 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
850 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700851 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700852 break;
853
Meng Wang1a7c35a2016-05-05 20:56:15 -0700854 case CMD_SET_ALLOWED_CARRIERS:
855 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800856 CarrierRestrictionRules argument =
857 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700858 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800859 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 break;
861
862 case EVENT_SET_ALLOWED_CARRIERS_DONE:
863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null && ar.result != null) {
866 request.result = ar.result;
867 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800868 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
869 if (ar.exception instanceof CommandException) {
870 loge("setAllowedCarriers: CommandException: " + ar.exception);
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
874 request.result =
875 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
876 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 } else {
878 loge("setAllowedCarriers: Unknown exception");
879 }
880 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700881 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 break;
883
884 case CMD_GET_ALLOWED_CARRIERS:
885 request = (MainThreadRequest) msg.obj;
886 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800887 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 break;
889
890 case EVENT_GET_ALLOWED_CARRIERS_DONE:
891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result;
895 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800896 request.result = new IllegalStateException(
897 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700898 if (ar.result == null) {
899 loge("getAllowedCarriers: Empty response");
900 } else if (ar.exception instanceof CommandException) {
901 loge("getAllowedCarriers: CommandException: " +
902 ar.exception);
903 } else {
904 loge("getAllowedCarriers: Unknown exception");
905 }
906 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700907 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
Nathan Haroldb3014052017-01-25 15:57:32 -0800910 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 request.result = new IllegalArgumentException(
917 "Failed to retrieve Forbidden Plmns");
918 if (ar.result == null) {
919 loge("getForbiddenPlmns: Empty response");
920 } else {
921 loge("getForbiddenPlmns: Unknown exception");
922 }
923 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700924 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 break;
926
927 case CMD_GET_FORBIDDEN_PLMNS:
928 request = (MainThreadRequest) msg.obj;
929 uiccCard = getUiccCardFromRequest(request);
930 if (uiccCard == null) {
931 loge("getForbiddenPlmns() UiccCard is null");
932 request.result = new IllegalArgumentException(
933 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700934 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 break;
936 }
937 Integer appType = (Integer) request.argument;
938 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
939 if (uiccApp == null) {
940 loge("getForbiddenPlmns() no app with specified type -- "
941 + appType);
942 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945 } else {
946 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
947 + " specified type -- " + appType);
948 }
949 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
950 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
951 onCompleted);
952 break;
953
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000954 case CMD_SWITCH_SLOTS:
955 request = (MainThreadRequest) msg.obj;
956 int[] physicalSlots = (int[]) request.argument;
957 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
958 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
959 break;
960
961 case EVENT_SWITCH_SLOTS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700965 notifyRequester(request);
966 break;
967 case CMD_GET_NETWORK_SELECTION_MODE:
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
970 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
971 break;
972
973 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 if (ar.exception != null) {
977 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
978 } else {
979 int mode = ((int[]) ar.result)[0];
980 if (mode == 0) {
981 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
982 } else {
983 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
984 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700986 notifyRequester(request);
987 break;
988 case CMD_GET_CDMA_ROAMING_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
991 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
992 break;
993 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 if (ar.exception != null) {
997 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
998 } else {
999 request.result = ((int[]) ar.result)[0];
1000 }
1001 notifyRequester(request);
1002 break;
1003 case CMD_SET_CDMA_ROAMING_MODE:
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1006 int mode = (int) request.argument;
1007 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1008 break;
1009 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 request.result = ar.exception == null;
1013 notifyRequester(request);
1014 break;
1015 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1018 int subscriptionMode = (int) request.argument;
1019 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1020 break;
1021 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
1024 request.result = ar.exception == null;
1025 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001026 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001027 case CMD_GET_ALL_CELL_INFO:
1028 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001029 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001030 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001032 case EVENT_GET_ALL_CELL_INFO_DONE:
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001035 // If a timeout occurs, the response will be null
1036 request.result = (ar.exception == null && ar.result != null)
1037 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 synchronized (request) {
1039 request.notifyAll();
1040 }
1041 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001042 case CMD_REQUEST_CELL_INFO_UPDATE:
1043 request = (MainThreadRequest) msg.obj;
1044 request.phone.requestCellInfoUpdate(request.workSource,
1045 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1046 break;
1047 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1051 try {
1052 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001053 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001054 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1055 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001057 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001058 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 } else {
1060 // use the result as returned
1061 cb.onCellInfo((List<CellInfo>) ar.result);
1062 }
1063 } catch (RemoteException re) {
1064 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1065 }
1066 break;
1067 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001068 request = (MainThreadRequest) msg.obj;
1069 WorkSource ws = (WorkSource) request.argument;
1070 Phone phone = getPhoneFromRequest(request);
1071 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 if (ar.exception == null) {
1077 request.result = ar.result;
1078 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1081 ? new CdmaCellLocation() : new GsmCellLocation();
1082 }
1083
1084 synchronized (request) {
1085 request.notifyAll();
1086 }
1087 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001088 case CMD_MODEM_REBOOT:
1089 request = (MainThreadRequest) msg.obj;
1090 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001091 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001092 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001093 case EVENT_CMD_MODEM_REBOOT_DONE:
1094 handleNullReturnEvent(msg, "rebootModem");
1095 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001096 case CMD_REQUEST_ENABLE_MODEM:
1097 request = (MainThreadRequest) msg.obj;
1098 boolean enable = (boolean) request.argument;
1099 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1100 PhoneConfigurationManager.getInstance()
1101 .enablePhone(request.phone, enable, onCompleted);
1102 break;
1103 case EVENT_ENABLE_MODEM_DONE:
1104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
1106 request.result = (ar.exception == null);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001107 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001108 notifyRequester(request);
1109 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 default:
1111 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1112 break;
1113 }
1114 }
Jake Hambye994d462014-02-03 13:10:13 -08001115
Pengquan Meng0c05b502018-09-06 09:59:22 -07001116 private void notifyRequester(MainThreadRequest request) {
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 }
1121
Jake Hambye994d462014-02-03 13:10:13 -08001122 private void handleNullReturnEvent(Message msg, String command) {
1123 AsyncResult ar = (AsyncResult) msg.obj;
1124 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1125 if (ar.exception == null) {
1126 request.result = true;
1127 } else {
1128 request.result = false;
1129 if (ar.exception instanceof CommandException) {
1130 loge(command + ": CommandException: " + ar.exception);
1131 } else {
1132 loge(command + ": Unknown exception");
1133 }
1134 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001135 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 }
1138
1139 /**
1140 * Posts the specified command to be executed on the main thread,
1141 * waits for the request to complete, and returns the result.
1142 * @see #sendRequestAsync
1143 */
1144 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001145 return sendRequest(
1146 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001147 }
1148
1149 /**
1150 * Posts the specified command to be executed on the main thread,
1151 * waits for the request to complete, and returns the result.
1152 * @see #sendRequestAsync
1153 */
1154 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1155 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001156 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001157 }
1158
1159 /**
1160 * Posts the specified command to be executed on the main thread,
1161 * waits for the request to complete, and returns the result.
1162 * @see #sendRequestAsync
1163 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001164 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001165 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001166 }
1167
1168 /**
1169 * Posts the specified command to be executed on the main thread,
1170 * waits for the request to complete, and returns the result.
1171 * @see #sendRequestAsync
1172 */
Nathan Harold92bed182018-10-12 18:16:49 -07001173 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1174 return sendRequest(command, argument, subId, null, workSource);
1175 }
1176
1177 /**
1178 * Posts the specified command to be executed on the main thread,
1179 * waits for the request to complete, and returns the result.
1180 * @see #sendRequestAsync
1181 */
1182 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1183 return sendRequest(
1184 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1185 }
1186
1187 /**
1188 * Posts the specified command to be executed on the main thread,
1189 * waits for the request to complete, and returns the result.
1190 * @see #sendRequestAsync
1191 */
1192 private Object sendRequest(
1193 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1195 throw new RuntimeException("This method will deadlock if called from the main thread.");
1196 }
1197
Nathan Harold92bed182018-10-12 18:16:49 -07001198 MainThreadRequest request = null;
1199 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1200 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1201 } else if (phone != null) {
1202 request = new MainThreadRequest(argument, phone, workSource);
1203 } else {
1204 request = new MainThreadRequest(argument, subId, workSource);
1205 }
1206
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 Message msg = mMainThreadHandler.obtainMessage(command, request);
1208 msg.sendToTarget();
1209
1210 // Wait for the request to complete
1211 synchronized (request) {
1212 while (request.result == null) {
1213 try {
1214 request.wait();
1215 } catch (InterruptedException e) {
1216 // Do nothing, go back and wait until the request is complete
1217 }
1218 }
1219 }
1220 return request.result;
1221 }
1222
1223 /**
1224 * Asynchronous ("fire and forget") version of sendRequest():
1225 * Posts the specified command to be executed on the main thread, and
1226 * returns immediately.
1227 * @see #sendRequest
1228 */
1229 private void sendRequestAsync(int command) {
1230 mMainThreadHandler.sendEmptyMessage(command);
1231 }
1232
1233 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001234 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001235 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001236 */
1237 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001238 sendRequestAsync(command, argument, null, null);
1239 }
1240
1241 /**
1242 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1243 * @see {@link #sendRequest(int,Object)}
1244 */
1245 private void sendRequestAsync(
1246 int command, Object argument, Phone phone, WorkSource workSource) {
1247 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001248 Message msg = mMainThreadHandler.obtainMessage(command, request);
1249 msg.sendToTarget();
1250 }
1251
1252 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 * Initialize the singleton PhoneInterfaceManager instance.
1254 * This is only done once, at startup, from PhoneApp.onCreate().
1255 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001256 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 synchronized (PhoneInterfaceManager.class) {
1258 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001259 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 } else {
1261 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1262 }
1263 return sInstance;
1264 }
1265 }
1266
1267 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001268 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001271 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1273 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001274 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001275 mTelephonySharedPreferences =
1276 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001277 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001278 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001279
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 publish();
1281 }
1282
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001283 private Phone getDefaultPhone() {
1284 Phone thePhone = getPhone(getDefaultSubscription());
1285 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1286 }
1287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 private void publish() {
1289 if (DBG) log("publish: " + this);
1290
1291 ServiceManager.addService("phone", this);
1292 }
1293
Stuart Scott584921c2015-01-15 17:10:34 -08001294 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001295 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001296 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001297 }
1298
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001299 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1300 Phone phone = getPhoneFromRequest(request);
1301 return phone == null ? null :
1302 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1303 }
1304
Wink Saville36469e72014-06-11 15:17:00 -07001305 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001306 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001307 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309
1310 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001311 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001312 }
1313
Wink Savilleb564aae2014-10-23 10:18:09 -07001314 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (DBG) log("dial: " + number);
1316 // No permission check needed here: This is just a wrapper around the
1317 // ACTION_DIAL intent, which is available to any app since it puts up
1318 // the UI before it does anything.
1319
Malcolm Chend965c8b2018-02-28 15:00:40 -08001320 final long identity = Binder.clearCallingIdentity();
1321 try {
1322 String url = createTelUrl(number);
1323 if (url == null) {
1324 return;
1325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326
Malcolm Chend965c8b2018-02-28 15:00:40 -08001327 // PENDING: should we just silently fail if phone is offhook or ringing?
1328 PhoneConstants.State state = mCM.getState(subId);
1329 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1330 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1331 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1332 mApp.startActivity(intent);
1333 }
1334 } finally {
1335 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 }
1337 }
1338
1339 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001340 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001341 }
1342
Wink Savilleb564aae2014-10-23 10:18:09 -07001343 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 if (DBG) log("call: " + number);
1345
1346 // This is just a wrapper around the ACTION_CALL intent, but we still
1347 // need to do a permission check since we're calling startActivity()
1348 // from the context of the phone app.
1349 enforceCallPermission();
1350
1351 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1352 != AppOpsManager.MODE_ALLOWED) {
1353 return;
1354 }
1355
Malcolm Chend965c8b2018-02-28 15:00:40 -08001356 final long identity = Binder.clearCallingIdentity();
1357 try {
1358 String url = createTelUrl(number);
1359 if (url == null) {
1360 return;
1361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362
Malcolm Chend965c8b2018-02-28 15:00:40 -08001363 boolean isValid = false;
1364 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1365 if (slist != null) {
1366 for (SubscriptionInfo subInfoRecord : slist) {
1367 if (subInfoRecord.getSubscriptionId() == subId) {
1368 isValid = true;
1369 break;
1370 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001371 }
Wink Saville08874612014-08-31 19:19:58 -07001372 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001373 if (!isValid) {
1374 return;
1375 }
Wink Saville08874612014-08-31 19:19:58 -07001376
Malcolm Chend965c8b2018-02-28 15:00:40 -08001377 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1378 intent.putExtra(SUBSCRIPTION_KEY, subId);
1379 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1380 mApp.startActivity(intent);
1381 } finally {
1382 Binder.restoreCallingIdentity(identity);
1383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 }
1385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001391 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001392 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1393 }
1394
1395 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001397 }
1398
Wink Savilleb564aae2014-10-23 10:18:09 -07001399 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001400 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001401 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1402 }
1403
1404 /** {@hide} */
1405 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001406 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001407 }
1408
Wink Savilleb564aae2014-10-23 10:18:09 -07001409 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001411
1412 final long identity = Binder.clearCallingIdentity();
1413 try {
1414 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1415 checkSimPin.start();
1416 return checkSimPin.unlockSim(null, pin);
1417 } finally {
1418 Binder.restoreCallingIdentity(identity);
1419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 }
1421
Wink Saville9de0f752013-10-22 19:04:03 -07001422 /** {@hide} */
1423 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001425 }
1426
Wink Savilleb564aae2014-10-23 10:18:09 -07001427 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001429
1430 final long identity = Binder.clearCallingIdentity();
1431 try {
1432 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1433 checkSimPuk.start();
1434 return checkSimPuk.unlockSim(puk, pin);
1435 } finally {
1436 Binder.restoreCallingIdentity(identity);
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 }
1439
1440 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001441 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 * a synchronous one.
1443 */
1444 private static class UnlockSim extends Thread {
1445
1446 private final IccCard mSimCard;
1447
1448 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001449 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1450 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451
1452 // For replies from SimCard interface
1453 private Handler mHandler;
1454
1455 // For async handler to identify request type
1456 private static final int SUPPLY_PIN_COMPLETE = 100;
1457
1458 public UnlockSim(IccCard simCard) {
1459 mSimCard = simCard;
1460 }
1461
1462 @Override
1463 public void run() {
1464 Looper.prepare();
1465 synchronized (UnlockSim.this) {
1466 mHandler = new Handler() {
1467 @Override
1468 public void handleMessage(Message msg) {
1469 AsyncResult ar = (AsyncResult) msg.obj;
1470 switch (msg.what) {
1471 case SUPPLY_PIN_COMPLETE:
1472 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1473 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001474 mRetryCount = msg.arg1;
1475 if (ar.exception != null) {
1476 if (ar.exception instanceof CommandException &&
1477 ((CommandException)(ar.exception)).getCommandError()
1478 == CommandException.Error.PASSWORD_INCORRECT) {
1479 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1480 } else {
1481 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1482 }
1483 } else {
1484 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 mDone = true;
1487 UnlockSim.this.notifyAll();
1488 }
1489 break;
1490 }
1491 }
1492 };
1493 UnlockSim.this.notifyAll();
1494 }
1495 Looper.loop();
1496 }
1497
1498 /*
1499 * Use PIN or PUK to unlock SIM card
1500 *
1501 * If PUK is null, unlock SIM card with PIN
1502 *
1503 * If PUK is not null, unlock SIM card with PUK and set PIN code
1504 */
Wink Saville9de0f752013-10-22 19:04:03 -07001505 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
1507 while (mHandler == null) {
1508 try {
1509 wait();
1510 } catch (InterruptedException e) {
1511 Thread.currentThread().interrupt();
1512 }
1513 }
1514 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1515
1516 if (puk == null) {
1517 mSimCard.supplyPin(pin, callback);
1518 } else {
1519 mSimCard.supplyPuk(puk, pin, callback);
1520 }
1521
1522 while (!mDone) {
1523 try {
1524 Log.d(LOG_TAG, "wait for done");
1525 wait();
1526 } catch (InterruptedException e) {
1527 // Restore the interrupted status
1528 Thread.currentThread().interrupt();
1529 }
1530 }
1531 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001532 int[] resultArray = new int[2];
1533 resultArray[0] = mResult;
1534 resultArray[1] = mRetryCount;
1535 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537 }
1538
1539 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001541
1542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 // No permission check needed here: this call is harmless, and it's
1546 // needed for the ServiceState.requestStateUpdate() call (which is
1547 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final Phone phone = getPhone(subId);
1551 if (phone != null) {
1552 phone.updateServiceLocation();
1553 }
1554 } finally {
1555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
1558
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 @Override
1560 public boolean isRadioOn(String callingPackage) {
1561 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001562 }
1563
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001564 @Override
1565 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001567 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001568 return false;
1569 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001570
1571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 return isRadioOnForSubscriber(subId);
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
1576 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001577 }
1578
1579 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001580 final long identity = Binder.clearCallingIdentity();
1581 try {
1582 final Phone phone = getPhone(subId);
1583 if (phone != null) {
1584 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1585 } else {
1586 return false;
1587 }
1588 } finally {
1589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
1593 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001594 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
Wink Saville36469e72014-06-11 15:17:00 -07001596
Wink Savilleb564aae2014-10-23 10:18:09 -07001597 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001599
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1605 }
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Wink Saville36469e72014-06-11 15:17:00 -07001609 }
1610
1611 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001612 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001613 }
1614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001616 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 final Phone phone = getPhone(subId);
1621 if (phone == null) {
1622 return false;
1623 }
1624 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1625 toggleRadioOnOffForSubscriber(subId);
1626 }
1627 return true;
1628 } finally {
1629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
Wink Saville36469e72014-06-11 15:17:00 -07001632
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001633 public boolean needMobileRadioShutdown() {
1634 /*
1635 * If any of the Radios are available, it will need to be
1636 * shutdown. So return true if any Radio is available.
1637 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1641 Phone phone = PhoneFactory.getPhone(i);
1642 if (phone != null && phone.isRadioAvailable()) return true;
1643 }
1644 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1645 return false;
1646 } finally {
1647 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001648 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001649 }
1650
Malcolm Chend965c8b2018-02-28 15:00:40 -08001651 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001652 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001653 enforceModifyPermission();
1654
1655 final long identity = Binder.clearCallingIdentity();
1656 try {
1657 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1658 logv("Shutting down Phone " + i);
1659 shutdownRadioUsingPhoneId(i);
1660 }
1661 } finally {
1662 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001663 }
1664 }
1665
1666 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001667 Phone phone = PhoneFactory.getPhone(phoneId);
1668 if (phone != null && phone.isRadioAvailable()) {
1669 phone.shutdownRadio();
1670 }
1671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001674 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1679 if (defaultPhone != null) {
1680 defaultPhone.setRadioPower(turnOn);
1681 return true;
1682 } else {
1683 loge("There's no default phone.");
1684 return false;
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001688 }
Wink Saville36469e72014-06-11 15:17:00 -07001689 }
1690
Wink Savilleb564aae2014-10-23 10:18:09 -07001691 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001693
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.setRadioPower(turnOn);
1699 return true;
1700 } else {
1701 return false;
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
Wink Saville36469e72014-06-11 15:17:00 -07001708 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 public boolean enableDataConnectivity() {
1711 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001712
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 int subId = mSubscriptionController.getDefaultDataSubId();
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001718 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Wink Saville36469e72014-06-11 15:17:00 -07001728 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public boolean disableDataConnectivity() {
1731 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 int subId = mSubscriptionController.getDefaultDataSubId();
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001738 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001739 return true;
1740 } else {
1741 return false;
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001749 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 final Phone phone = getPhone(subId);
1753 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001754 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001755 } else {
1756 return false;
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
1763 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
pkanwarae03a6b2016-11-06 20:37:09 -08001767 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001768 enforceCallPermission();
1769
1770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1773 return;
1774 }
1775 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1776 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
1779 }
pkanwar32d516d2016-10-14 19:37:38 -07001780 };
1781
Wink Savilleb564aae2014-10-23 10:18:09 -07001782 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001784
1785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1788 return false;
1789 }
1790 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1791 } finally {
1792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001797 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001798 }
1799
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 Phone phone = PhoneFactory.getPhone(slotIndex);
1804 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1805 PhoneConstantConversions.convertCallState(phone.getState());
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1816 if (phone != null) {
1817 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1818 } else {
1819 return PhoneConstantConversions.convertDataState(
1820 PhoneConstants.DataState.DISCONNECTED);
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1832 if (phone != null) {
1833 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1834 } else {
1835 return TelephonyManager.DATA_ACTIVITY_NONE;
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
1842 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001843 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001844 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001845 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001846 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1847 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001848 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001851 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 if (DBG_LOC) log("getCellLocation: is active user");
1855 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001856 int subId = mSubscriptionController.getDefaultDataSubId();
1857 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1858 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001859 return data;
1860 } finally {
1861 Binder.restoreCallingIdentity(identity);
1862 }
Svetoslav64fad262015-04-14 14:35:21 -07001863 }
1864
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001866 public String getNetworkCountryIsoForPhone(int phoneId) {
1867 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1868 // registered cell info, so return a NULL country instead.
1869 final long identity = Binder.clearCallingIdentity();
1870 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001871 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1872 // Get default phone in this case.
1873 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1874 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001875 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001876 // Todo: fix this when we can get the actual cellular network info when the device
1877 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001878 if (TelephonyManager.NETWORK_TYPE_IWLAN
1879 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1880 return "";
1881 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001882 Phone phone = PhoneFactory.getPhone(phoneId);
1883 if (phone != null) {
1884 ServiceStateTracker sst = phone.getServiceStateTracker();
1885 if (sst != null) {
1886 LocaleTracker lt = sst.getLocaleTracker();
1887 if (lt != null) {
1888 return lt.getCurrentCountry();
1889 }
1890 }
1891 }
1892 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001896 }
1897
1898 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001900 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001901 }
1902
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001904 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 mApp.enforceCallingOrSelfPermission(
1906 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001907
1908 final long identity = Binder.clearCallingIdentity();
1909 try {
1910 final Phone phone = getPhone(subId);
1911 if (phone != null) {
1912 phone.enableLocationUpdates();
1913 }
1914 } finally {
1915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919 @Override
1920 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001921 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001925 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 mApp.enforceCallingOrSelfPermission(
1927 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 final Phone phone = getPhone(subId);
1932 if (phone != null) {
1933 phone.disableLocationUpdates();
1934 }
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Nathan Harold31d7ff32018-10-15 20:20:30 -07001940 /**
1941 * Returns the target SDK version number for a given package name.
1942 *
1943 * @return target SDK if the package is found or INT_MAX.
1944 */
1945 private int getTargetSdk(String packageName) {
1946 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001947 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1948 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001949 if (ai != null) return ai.targetSdkVersion;
1950 } catch (PackageManager.NameNotFoundException unexpected) {
1951 }
1952 return Integer.MAX_VALUE;
1953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 @Override
1956 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001957 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1958 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001959 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1960 throw new SecurityException(
1961 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1962 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001963
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1965 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1966 return null;
1967 }
Svetoslav64fad262015-04-14 14:35:21 -07001968
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001969 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970
Nathan Haroldf180aac2018-06-01 18:43:55 -07001971 List<CellInfo> info = getAllCellInfo(callingPackage);
1972 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973
Nathan Haroldf180aac2018-06-01 18:43:55 -07001974 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1975 for (CellInfo ci : info) {
1976 if (ci instanceof CellInfoGsm) {
1977 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1978 } else if (ci instanceof CellInfoWcdma) {
1979 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001982 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001985 private List<CellInfo> getCachedCellInfo() {
1986 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1987 for (Phone phone : PhoneFactory.getPhones()) {
1988 List<CellInfo> info = phone.getAllCellInfo();
1989 if (info != null) cellInfos.addAll(info);
1990 }
1991 return cellInfos;
1992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993
1994 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001995 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001996 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001997 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001998 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001999 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07002000 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002003 final int targetSdk = getTargetSdk(callingPackage);
2004 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2005 return getCachedCellInfo();
2006 }
2007
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002008 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002010 final long identity = Binder.clearCallingIdentity();
2011 try {
2012 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2013 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002014 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002015 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002016 if (info != null) cellInfos.addAll(info);
2017 }
2018 return cellInfos;
2019 } finally {
2020 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
2022 }
2023
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002024 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002025 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2026 requestCellInfoUpdateInternal(
2027 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2028 }
2029
2030 @Override
2031 public void requestCellInfoUpdateWithWorkSource(
2032 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2033 enforceModifyPermission();
2034 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2035 }
2036
2037 private void requestCellInfoUpdateInternal(
2038 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002039 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002040 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002041 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2042 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002043 return;
2044 }
2045
2046 final Phone phone = getPhone(subId);
2047 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2048
2049 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2050 }
2051
2052 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002054 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002056
2057 final long identity = Binder.clearCallingIdentity();
2058 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002059 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002060 } finally {
2061 Binder.restoreCallingIdentity(identity);
2062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 }
2064
Shishir Agrawala9f32182016-04-12 12:00:16 -07002065 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002066 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002067 Phone phone = PhoneFactory.getPhone(slotIndex);
2068 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002069 return null;
2070 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002071 int subId = phone.getSubId();
2072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2073 mApp, subId, callingPackage, "getImeiForSlot")) {
2074 return null;
2075 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 return phone.getImei();
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002083 }
2084
2085 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002086 public String getTypeAllocationCodeForSlot(int slotIndex) {
2087 Phone phone = PhoneFactory.getPhone(slotIndex);
2088 String tac = null;
2089 if (phone != null) {
2090 String imei = phone.getImei();
2091 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2092 }
2093 return tac;
2094 }
2095
2096 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002097 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002098 Phone phone = PhoneFactory.getPhone(slotIndex);
2099 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002100 return null;
2101 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002102
Jeff Davidson913390f2018-02-23 17:11:49 -08002103 int subId = phone.getSubId();
2104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2105 mApp, subId, callingPackage, "getMeidForSlot")) {
2106 return null;
2107 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002108
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 return phone.getMeid();
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
2114 }
Jack Yu2af8d712017-03-15 17:14:14 -07002115 }
2116
2117 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002118 public String getManufacturerCodeForSlot(int slotIndex) {
2119 Phone phone = PhoneFactory.getPhone(slotIndex);
2120 String manufacturerCode = null;
2121 if (phone != null) {
2122 String meid = phone.getMeid();
2123 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2124 }
2125 return manufacturerCode;
2126 }
2127
2128 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002129 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002130 Phone phone = PhoneFactory.getPhone(slotIndex);
2131 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002132 return null;
2133 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002134 int subId = phone.getSubId();
2135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2136 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2137 return null;
2138 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002139
2140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 return phone.getDeviceSvn();
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
2145 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002146 }
2147
fionaxu43304da2017-11-27 22:51:16 -08002148 @Override
2149 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = getPhone(subId);
2153 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
2156 }
fionaxu43304da2017-11-27 22:51:16 -08002157 }
2158
2159 @Override
2160 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002161 final long identity = Binder.clearCallingIdentity();
2162 try {
2163 final Phone phone = getPhone(subId);
2164 return phone == null ? null : phone.getCarrierName();
2165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
fionaxu43304da2017-11-27 22:51:16 -08002168 }
2169
calvinpaneed9ae82018-11-01 19:43:06 +08002170 @Override
chen xuc93cc282018-11-04 17:17:00 -08002171 public int getSubscriptionPreciseCarrierId(int subId) {
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 final Phone phone = getPhone(subId);
2175 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2176 : phone.getPreciseCarrierId();
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
2179 }
2180 }
2181
2182 @Override
2183 public String getSubscriptionPreciseCarrierName(int subId) {
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 final Phone phone = getPhone(subId);
2187 return phone == null ? null : phone.getPreciseCarrierName();
2188 } finally {
2189 Binder.restoreCallingIdentity(identity);
2190 }
2191 }
2192
chen xu02581692018-11-11 19:03:44 -08002193 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002194 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2195 if (!isSubscriptionMccMnc) {
2196 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2197 }
chen xu02581692018-11-11 19:03:44 -08002198 final Phone phone = PhoneFactory.getPhone(slotIndex);
2199 if (phone == null) {
2200 return TelephonyManager.UNKNOWN_CARRIER_ID;
2201 }
2202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2205 } finally {
2206 Binder.restoreCallingIdentity(identity);
2207 }
2208 }
2209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 //
2211 // Internal helper methods.
2212 //
2213
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002214 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2216 *
2217 * @throws SecurityException if the caller does not have the required permission
2218 */
2219 private void enforceModifyPermission() {
2220 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2221 }
2222
2223 /**
2224 * Make sure the caller has the CALL_PHONE permission.
2225 *
2226 * @throws SecurityException if the caller does not have the required permission
2227 */
2228 private void enforceCallPermission() {
2229 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2230 }
2231
Stuart Scott8eef64f2015-04-08 15:13:54 -07002232 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002233 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002234 "ConnectivityService");
2235 }
2236
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 private String createTelUrl(String number) {
2238 if (TextUtils.isEmpty(number)) {
2239 return null;
2240 }
2241
Jake Hambye994d462014-02-03 13:10:13 -08002242 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 }
2244
Ihab Awadf9e92732013-12-05 18:02:52 -08002245 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2247 }
2248
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002249 private static void logv(String msg) {
2250 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2251 }
2252
Ihab Awadf9e92732013-12-05 18:02:52 -08002253 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2255 }
2256
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002259 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002260 }
2261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002263 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 final Phone phone = PhoneFactory.getPhone(slotIndex);
2267 if (phone == null) {
2268 return PhoneConstants.PHONE_TYPE_NONE;
2269 } else {
2270 return phone.getPhoneType();
2271 }
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
2277 /**
2278 * Returns the CDMA ERI icon index to display
2279 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 @Override
2281 public int getCdmaEriIconIndex(String callingPackage) {
2282 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002283 }
2284
Sanket Padawe356d7632015-06-22 14:03:32 -07002285 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002286 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002288 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002289 return -1;
2290 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 final Phone phone = getPhone(subId);
2295 if (phone != null) {
2296 return phone.getCdmaEriIconIndex();
2297 } else {
2298 return -1;
2299 }
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
2305 /**
2306 * Returns the CDMA ERI icon mode,
2307 * 0 - ON
2308 * 1 - FLASHING
2309 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 @Override
2311 public int getCdmaEriIconMode(String callingPackage) {
2312 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002318 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 return -1;
2320 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 final Phone phone = getPhone(subId);
2325 if (phone != null) {
2326 return phone.getCdmaEriIconMode();
2327 } else {
2328 return -1;
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 text,
2337 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 @Override
2339 public String getCdmaEriText(String callingPackage) {
2340 return getCdmaEriTextForSubscriber(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 String getCdmaEriTextForSubscriber(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, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 return null;
2348 }
Malcolm Chend965c8b2018-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.getCdmaEriText();
2355 } else {
2356 return null;
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 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002364 * Returns the CDMA MDN.
2365 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002366 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2369 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002374 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002375 return phone.getLine1Number();
2376 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002377 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002378 return null;
2379 }
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002382 }
2383 }
2384
2385 /**
2386 * Returns the CDMA MIN.
2387 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002389 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2391 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002392
2393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2397 return phone.getCdmaMin();
2398 } else {
2399 return null;
2400 }
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002403 }
2404 }
2405
Hall Liud892bec2018-11-30 14:51:45 -08002406 @Override
2407 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2408 INumberVerificationCallback callback, String callingPackage) {
2409 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2410 != PERMISSION_GRANTED) {
2411 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2412 }
2413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2414
2415 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2416 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2417 throw new SecurityException("Calling package must be configured in the device config");
2418 }
2419
2420 if (range == null) {
2421 throw new NullPointerException("Range must be non-null");
2422 }
2423
2424 timeoutMillis = Math.min(timeoutMillis,
2425 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2426
2427 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2428 }
2429
Junda Liuca05d5d2014-08-14 22:36:34 -07002430 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 * Returns true if CDMA provisioning needs to run.
2432 */
2433 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002436 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002437 } finally {
2438 Binder.restoreCallingIdentity(identity);
2439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 }
2441
2442 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002443 * Sets the voice mail number of a given subId.
2444 */
2445 @Override
2446 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002447 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2452 new Pair<String, String>(alphaTag, number), new Integer(subId));
2453 return success;
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
2456 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002457 }
2458
Ta-wei Yen87c49842016-05-13 21:19:52 -07002459 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002460 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002462 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002463 if (!TextUtils.equals(callingPackage, systemDialer)) {
2464 throw new SecurityException("caller must be system dialer");
2465 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2470 if (phoneAccountHandle == null) {
2471 return null;
2472 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002473 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002476 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002477 }
2478
2479 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002480 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002483 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002484 return null;
2485 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002486
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002487 final long identity = Binder.clearCallingIdentity();
2488 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002489 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002493 }
2494
2495 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002496 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2497 VisualVoicemailSmsFilterSettings settings) {
2498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002503 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002504 } finally {
2505 Binder.restoreCallingIdentity(identity);
2506 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002507 }
2508
2509 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002510 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002516 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002517 } finally {
2518 Binder.restoreCallingIdentity(identity);
2519 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002520 }
2521
2522 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002523 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2524 String callingPackage, int subId) {
2525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002530 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531 } finally {
2532 Binder.restoreCallingIdentity(identity);
2533 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002534 }
2535
2536 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002537 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002538 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002543 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002547 }
2548
2549 @Override
2550 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2551 String number, int port, String text, PendingIntent sentIntent) {
2552 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002553 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002554 enforceSendSmsPermission();
2555 // Make the calls as the phone process.
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2559 if (port == 0) {
2560 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2561 sentIntent, null, false);
2562 } else {
2563 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2564 smsManager.sendDataMessageWithSelfPermissions(number, null,
2565 (short) port, data, sentIntent, null);
2566 }
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002570 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002571 /**
fionaxu0152e512016-11-14 13:36:14 -08002572 * Sets the voice activation state of a given subId.
2573 */
2574 @Override
2575 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2577 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone phone = getPhone(subId);
2582 if (phone != null) {
2583 phone.setVoiceActivationState(activationState);
2584 } else {
2585 loge("setVoiceActivationState fails with invalid subId: " + subId);
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002589 }
2590 }
2591
2592 /**
2593 * Sets the data activation state of a given subId.
2594 */
2595 @Override
2596 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2598 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(subId);
2603 if (phone != null) {
2604 phone.setDataActivationState(activationState);
2605 } else {
2606 loge("setVoiceActivationState fails with invalid subId: " + subId);
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002610 }
2611 }
2612
2613 /**
2614 * Returns the voice activation state of a given subId.
2615 */
2616 @Override
2617 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002618 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002619
fionaxu0152e512016-11-14 13:36:14 -08002620 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 if (phone != null) {
2624 return phone.getVoiceActivationState();
2625 } else {
2626 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2627 }
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002630 }
2631 }
2632
2633 /**
2634 * Returns the data activation state of a given subId.
2635 */
2636 @Override
2637 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002638 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639
fionaxu0152e512016-11-14 13:36:14 -08002640 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 if (phone != null) {
2644 return phone.getDataActivationState();
2645 } else {
2646 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002650 }
2651 }
2652
2653 /**
Wink Saville36469e72014-06-11 15:17:00 -07002654 * Returns the unread count of voicemails for a subId
2655 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002656 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002657 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2659 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2660 return 0;
2661 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 return phone.getVoiceMessageCount();
2667 } else {
2668 return 0;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002676 * returns true, if the device is in a state where both voice and data
2677 * are supported simultaneously. This can change based on location or network condition.
2678 */
2679 @Override
2680 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 final Phone phone = getPhone(subId);
2684 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
2687 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002688 }
2689
2690 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002691 * Send the dialer code if called from the current default dialer or the caller has
2692 * carrier privilege.
2693 * @param inputCode The dialer code to send
2694 */
2695 @Override
2696 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002697 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002699 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2700 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002701 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002702 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2703 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002704 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002708 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002709 } finally {
2710 Binder.restoreCallingIdentity(identity);
2711 }
fionaxu235cc5e2017-03-06 22:25:57 -08002712 }
2713
2714 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002715 * Returns the data network type.
2716 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 *
2718 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2719 */
2720 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002721 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 final Phone phone = getPhone(getDefaultSubscription());
2725 if (phone != null) {
2726 return phone.getServiceState().getDataNetworkType();
2727 } else {
2728 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002732 }
Wink Saville36469e72014-06-11 15:17:00 -07002733 }
2734
Pengquan Meng0c05b502018-09-06 09:59:22 -07002735 @Override
2736 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002737 if (!isActiveSubscription(subId)) {
2738 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2739 }
2740
Pengquan Meng0c05b502018-09-06 09:59:22 -07002741 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2742 }
2743
Brad Ebinger4c460712018-10-01 10:40:55 -07002744 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002745 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2746 throws RemoteException {
2747 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002748 final long token = Binder.clearCallingIdentity();
2749 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002751 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002752 .addRegistrationCallbackForSubscription(c, subId);
2753 } finally {
2754 Binder.restoreCallingIdentity(token);
2755 }
2756 }
2757
2758 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002759 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2760 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2762 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2763 }
2764 Binder.withCleanCallingIdentity(() -> {
2765 try {
2766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002767 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002768 .removeRegistrationCallbackForSubscription(c, subId);
2769 } catch (IllegalArgumentException e) {
2770 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2771 + "is inactive, ignoring unregister.");
2772 // If the subscription is no longer active, just return, since the callback
2773 // will already have been removed internally.
2774 }
2775 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002776 }
2777
2778 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002779 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2780 throws RemoteException {
2781 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002782 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2783 final long token = Binder.clearCallingIdentity();
2784 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002785 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002786 .addCapabilitiesCallbackForSubscription(c, subId);
2787 } finally {
2788 Binder.restoreCallingIdentity(token);
2789 }
2790 }
2791
2792 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002793 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2794 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002795
2796 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2797 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2798 }
2799 Binder.withCleanCallingIdentity(() -> {
2800 try {
2801 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002802 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002803 .removeCapabilitiesCallbackForSubscription(c, subId);
2804 } catch (IllegalArgumentException e) {
2805 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2806 + "is inactive, ignoring unregister.");
2807 // If the subscription is no longer active, just return, since the callback
2808 // will already have been removed internally.
2809 }
2810 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002811 }
2812
2813 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002814 public boolean isCapable(int subId, int capability, int regTech) {
2815 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002816 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2817 final long token = Binder.clearCallingIdentity();
2818 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002819 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002820 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2821 } catch (ImsException e) {
2822 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2823 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002824 } catch (IllegalArgumentException e) {
2825 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2826 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002827 } finally {
2828 Binder.restoreCallingIdentity(token);
2829 }
2830 }
2831
2832 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002833 public boolean isAvailable(int subId, int capability, int regTech) {
2834 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002835 final long token = Binder.clearCallingIdentity();
2836 try {
2837 Phone phone = getPhone(subId);
2838 if (phone == null) return false;
2839 return phone.isImsCapabilityAvailable(capability, regTech);
2840 } finally {
2841 Binder.restoreCallingIdentity(token);
2842 }
2843 }
2844
2845 @Override
2846 public boolean isAdvancedCallingSettingEnabled(int subId) {
2847 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2849 final long token = Binder.clearCallingIdentity();
2850 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002851 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002852 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2853 } finally {
2854 Binder.restoreCallingIdentity(token);
2855 }
2856 }
2857
2858 @Override
2859 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2861 "setAdvancedCallingSetting");
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002865 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002866 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002873 public boolean isVtSettingEnabled(int subId) {
2874 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002878 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002879 getSlotIndexOrException(subId)).isVtEnabledByUser();
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
2885 @Override
2886 public void setVtSetting(int subId, boolean isEnabled) {
2887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2888 "setVtSetting");
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002893 } finally {
2894 Binder.restoreCallingIdentity(identity);
2895 }
2896 }
2897
2898 @Override
2899 public boolean isVoWiFiSettingEnabled(int subId) {
2900 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002904 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002905 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 }
2910
2911 @Override
2912 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2914 "setVoWiFiSetting");
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002918 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
2922 }
2923
2924 @Override
2925 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2926 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002930 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002931 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
2935 }
2936
2937 @Override
2938 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2940 "setVoWiFiRoamingSetting");
2941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002944 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002945 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
2948 }
2949 }
2950
2951 @Override
2952 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2954 "setVoWiFiNonPersistent");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002958 boolean isRoaming = TelephonyManager.from(
2959 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002960 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002961 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07002962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 @Override
2968 public int getVoWiFiModeSetting(int subId) {
2969 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002973 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002974 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
2978 }
2979
2980 @Override
2981 public void setVoWiFiModeSetting(int subId, int mode) {
2982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2983 "setVoWiFiModeSetting");
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002987 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002988 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
2994 @Override
2995 public int getVoWiFiRoamingModeSetting(int subId) {
2996 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003000 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003001 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
3008 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3010 "setVoWiFiRoamingModeSetting");
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003014 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003015 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 }
3020
3021 @Override
3022 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3024 "setRttCapabilityEnabled");
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003028 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003029 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
3033 }
3034
3035 @Override
3036 public boolean isTtyOverVolteEnabled(int subId) {
3037 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003041 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003042 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
3046 }
3047
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003048 @Override
3049 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3050 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003055 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
3059 }
3060
3061 @Override
3062 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3063 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3064 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003065 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3066 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3067 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003068 try {
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003070 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003071 .removeProvisioningCallbackForSubscription(callback, subId);
3072 } catch (IllegalArgumentException e) {
3073 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3074 + "is inactive, ignoring unregister.");
3075 // If the subscription is no longer active, just return, since the callback will already
3076 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
3080 }
3081
3082 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003083 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3084 boolean isProvisioned) {
3085 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3086 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3087 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3088 }
3089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3090 "setProvisioningStatusForCapability");
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3094 Phone phone = getPhone(subId);
3095 if (phone == null) {
3096 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3097 + subId);
3098 return;
3099 }
3100 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3101 return;
3102 }
3103
3104 // this capability requires provisioning, route to the correct API.
3105 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3106 switch (capability) {
3107 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3108 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3109 ims.setVolteProvisioned(isProvisioned);
3110 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3111 ims.setWfcProvisioned(isProvisioned);
3112 }
3113 break;
3114 }
3115 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3116 // There is currently no difference in VT provisioning type.
3117 ims.setVtProvisioned(isProvisioned);
3118 break;
3119 }
3120 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3121 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3122 // change the capability of the feature instead if needed.
3123 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3124 == isProvisioned) {
3125 // No change in provisioning.
3126 return;
3127 }
3128 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3129 try {
3130 ims.changeMmTelCapability(capability, tech, isProvisioned);
3131 } catch (ImsException e) {
3132 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3133 + ", Exception" + e.getMessage());
3134 }
3135 break;
3136 }
3137 default: {
3138 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3139 + capability + "', which does not require provisioning.");
3140 }
3141 }
3142
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 @Override
3149 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3150 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3151 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3152 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3153 }
3154 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3158 Phone phone = getPhone(subId);
3159 if (phone == null) {
3160 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3161 + subId);
3162 // We will fail with "true" as the provisioning status because this is the default
3163 // if we do not require provisioning.
3164 return true;
3165 }
3166
3167 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3168 return true;
3169 }
3170
3171 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3172 switch (capability) {
3173 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3174 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3175 return ims.isVolteProvisionedOnDevice();
3176 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3177 return ims.isWfcProvisionedOnDevice();
3178 }
3179 // This should never happen, since we are checking tech above to make sure it
3180 // is either LTE or IWLAN.
3181 throw new IllegalArgumentException("Invalid radio technology for voice "
3182 + "capability.");
3183 }
3184 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3185 // There is currently no difference in VT provisioning type.
3186 return ims.isVtProvisionedOnDevice();
3187 }
3188 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3189 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3190 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3191 }
3192 default: {
3193 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3194 + capability + "', which does not require provisioning.");
3195 }
3196 }
3197
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
3203 @Override
3204 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3205 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3206 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3207 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3208 }
3209 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3210 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3211 return (provisionedBits & capability) > 0;
3212 }
3213
3214 @Override
3215 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3216 boolean isProvisioned) {
3217 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3218 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3219 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3220 }
3221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3222 "setProvisioningStatusForCapability");
3223 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3224 // If the current provisioning status for capability already matches isProvisioned,
3225 // do nothing.
3226 if (((provisionedBits & capability) > 0) == isProvisioned) {
3227 return;
3228 }
3229 if (isProvisioned) {
3230 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3231 } else {
3232 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3233 }
3234 }
3235
3236 /**
3237 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3238 * technology. The bitfield should mirror the bitfield defined by
3239 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3240 */
3241 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3242 String key = getMmTelProvisioningKey(subId, tech);
3243 // Default is no capabilities are provisioned.
3244 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3245 }
3246
3247 /**
3248 * Sets the MmTel capability provisioning bitfield (defined by
3249 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3250 * technology specified.
3251 *
3252 * Note: This is a synchronous command and should not be called on UI thread.
3253 */
3254 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3255 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3256 String key = getMmTelProvisioningKey(subId, tech);
3257 editor.putInt(key, newField);
3258 editor.commit();
3259 }
3260
3261 private static String getMmTelProvisioningKey(int subId, int tech) {
3262 // resulting key is provision_ims_mmtel_{subId}_{tech}
3263 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3264 }
3265
3266 /**
3267 * Query CarrierConfig to see if the specified capability requires provisioning for the
3268 * carrier associated with the subscription id.
3269 */
3270 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3271 int capability) {
3272 CarrierConfigManager configManager = new CarrierConfigManager(context);
3273 PersistableBundle c = configManager.getConfigForSubId(subId);
3274 boolean requireUtProvisioning = c.getBoolean(
3275 // By default, this config is true (even if there is no SIM). We also check to make
3276 // sure the subscription needs provisioning here, so we do not need to check for
3277 // the no-SIM case, where we would normally shortcut this to false.
3278 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3279 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3280 false);
3281 boolean requireVoiceVtProvisioning = c.getBoolean(
3282 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3283
3284 // First check to make sure that the capability requires provisioning.
3285 switch (capability) {
3286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3287 // intentional fallthrough
3288 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3289 if (requireVoiceVtProvisioning) {
3290 // Voice and Video requires provisioning
3291 return true;
3292 }
3293 break;
3294 }
3295 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3296 if (requireUtProvisioning) {
3297 // UT requires provisioning
3298 return true;
3299 }
3300 break;
3301 }
3302 }
3303 return false;
3304 }
3305
3306 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003307 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003308 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3309 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3310 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003311 enforceReadPrivilegedPermission("getImsProvisioningInt");
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003315 int slotId = getSlotIndex(subId);
3316 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3317 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3318 + subId + "' for key:" + key);
3319 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3320 }
3321 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003322 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003323 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3324 + subId + "' for key:" + key);
3325 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
3329 }
3330
3331 @Override
3332 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003333 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3334 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3335 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003336 enforceReadPrivilegedPermission("getImsProvisioningString");
3337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003340 int slotId = getSlotIndex(subId);
3341 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3342 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3343 + subId + "' for key:" + key);
3344 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3345 }
3346 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003347 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003348 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3349 + subId + "' for key:" + key);
3350 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
3357 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003358 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3359 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3360 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3362 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003366 int slotId = getSlotIndex(subId);
3367 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3368 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3369 + subId + "' for key:" + key);
3370 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3371 }
3372 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003373 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003374 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3375 + "' for key:" + key);
3376 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
3380 }
3381
3382 @Override
3383 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3385 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3386 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3388 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003392 int slotId = getSlotIndex(subId);
3393 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3394 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3395 + subId + "' for key:" + key);
3396 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3397 }
3398 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003400 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3401 + "' for key:" + key);
3402 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
3406 }
3407
Brad Ebinger4c460712018-10-01 10:40:55 -07003408 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3409 int slotId = SubscriptionManager.getSlotIndex(subId);
3410 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003411 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003412 }
3413 return slotId;
3414 }
3415
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003416 private int getSlotIndex(int subId) {
3417 int slotId = SubscriptionManager.getSlotIndex(subId);
3418 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3419 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3420 }
3421 return slotId;
3422 }
3423
Wink Saville36469e72014-06-11 15:17:00 -07003424 /**
3425 * Returns the network type for a subId
3426 */
3427 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003428 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003430 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003431 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3432 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003433
Malcolm Chend965c8b2018-02-28 15:00:40 -08003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 final Phone phone = getPhone(subId);
3437 if (phone != null) {
3438 return phone.getServiceState().getDataNetworkType();
3439 } else {
3440 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3441 }
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
3447 /**
3448 * Returns the data network type
3449 */
3450 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003451 public int getDataNetworkType(String callingPackage) {
3452 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003453 }
3454
3455 /**
3456 * Returns the data network type for a subId
3457 */
3458 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003459 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003461 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003462 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3463 }
3464
Malcolm Chend965c8b2018-02-28 15:00:40 -08003465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 final Phone phone = getPhone(subId);
3468 if (phone != null) {
3469 return phone.getServiceState().getDataNetworkType();
3470 } else {
3471 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3472 }
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 }
3477
3478 /**
Wink Saville36469e72014-06-11 15:17:00 -07003479 * Returns the Voice network type for a subId
3480 */
3481 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003482 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003484 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003485 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3486 }
3487
Malcolm Chend965c8b2018-02-28 15:00:40 -08003488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 final Phone phone = getPhone(subId);
3491 if (phone != null) {
3492 return phone.getServiceState().getVoiceNetworkType();
3493 } else {
3494 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3495 }
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 }
3500
3501 /**
3502 * @return true if a ICC card is present
3503 */
3504 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003505 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003506 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3507 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003508 }
3509
3510 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003511 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003512 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003513 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003514 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 final Phone phone = PhoneFactory.getPhone(slotIndex);
3518 if (phone != null) {
3519 return phone.getIccCard().hasIccCard();
3520 } else {
3521 return false;
3522 }
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
3528 /**
3529 * Return if the current radio is LTE on CDMA. This
3530 * is a tri-state return value as for a period of time
3531 * the mode may be unknown.
3532 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003535 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003537 @Override
3538 public int getLteOnCdmaMode(String callingPackage) {
3539 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003540 }
3541
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003543 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003546 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3547 }
3548
Malcolm Chend965c8b2018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = getPhone(subId);
3552 if (phone == null) {
3553 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3554 } else {
3555 return phone.getLteOnCdmaMode();
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 }
Wink Saville36469e72014-06-11 15:17:00 -07003560 }
3561
Wink Saville36469e72014-06-11 15:17:00 -07003562 /**
3563 * {@hide}
3564 * Returns Default subId, 0 in the case of single standby.
3565 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003566 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003567 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003568 }
3569
Shishir Agrawala9f32182016-04-12 12:00:16 -07003570 private int getSlotForDefaultSubscription() {
3571 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3572 }
3573
Wink Savilleb564aae2014-10-23 10:18:09 -07003574 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003575 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003577
Pengquan Meng466e2482018-09-21 15:54:48 -07003578 private boolean isActiveSubscription(int subId) {
3579 return mSubscriptionController.isActiveSubId(subId);
3580 }
3581
Ihab Awadf2177b72013-11-25 13:33:23 -08003582 /**
3583 * @see android.telephony.TelephonyManager.WifiCallingChoices
3584 */
3585 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003586 final long identity = Binder.clearCallingIdentity();
3587 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003588 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003589 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3590 getWhenToMakeWifiCallsDefaultPreference());
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003594 }
3595
3596 /**
3597 * @see android.telephony.TelephonyManager.WifiCallingChoices
3598 */
3599 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003603 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003604 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003608 }
3609
Sailesh Nepald1e68152013-12-12 19:08:02 -08003610 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003611 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003612 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003613 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003614
Shishir Agrawal566b7612013-10-28 14:41:00 -07003615 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003616 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3617 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3619 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003621
Malcolm Chend965c8b2018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 if (TextUtils.equals(ISDR_AID, aid)) {
3625 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003626 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3627 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003628 if (bestComponent == null
3629 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3630 loge("The calling package is not allowed to access ISD-R.");
3631 throw new SecurityException(
3632 "The calling package is not allowed to access ISD-R.");
3633 }
Derek Tan740e1672017-06-27 14:56:27 -07003634 }
Derek Tan740e1672017-06-27 14:56:27 -07003635
Malcolm Chend965c8b2018-02-28 15:00:40 -08003636 if (DBG) {
3637 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3638 }
3639 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3640 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3641 if (DBG) log("iccOpenLogicalChannel: " + response);
3642 return response;
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003646 }
3647
3648 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003649 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3651 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003652
Malcolm Chend965c8b2018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3656 if (channel < 0) {
3657 return false;
3658 }
3659 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3660 if (DBG) log("iccCloseLogicalChannel: " + success);
3661 return success;
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003664 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003665 }
3666
3667 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003668 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003669 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003672
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 if (DBG) {
3676 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3677 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3678 + p3 + " data=" + data);
3679 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003680
Malcolm Chend965c8b2018-02-28 15:00:40 -08003681 if (channel < 0) {
3682 return "";
3683 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003684
Malcolm Chend965c8b2018-02-28 15:00:40 -08003685 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3686 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3687 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003688
Malcolm Chend965c8b2018-02-28 15:00:40 -08003689 // Append the returned status code to the end of the response payload.
3690 String s = Integer.toHexString(
3691 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3692 if (response.payload != null) {
3693 s = IccUtils.bytesToHexString(response.payload) + s;
3694 }
3695 return s;
3696 } finally {
3697 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003698 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003699 }
Jake Hambye994d462014-02-03 13:10:13 -08003700
Evan Charltonc66da362014-05-16 14:06:40 -07003701 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003702 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3703 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3705 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003707
Malcolm Chend965c8b2018-02-28 15:00:40 -08003708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3711 && TextUtils.equals(ISDR_AID, data)) {
3712 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003713 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3714 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003715 if (bestComponent == null
3716 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3717 loge("The calling package is not allowed to select ISD-R.");
3718 throw new SecurityException(
3719 "The calling package is not allowed to select ISD-R.");
3720 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003721 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003722
Malcolm Chend965c8b2018-02-28 15:00:40 -08003723 if (DBG) {
3724 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3725 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3726 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003727
Malcolm Chend965c8b2018-02-28 15:00:40 -08003728 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3729 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3730 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003731
Malcolm Chend965c8b2018-02-28 15:00:40 -08003732 // Append the returned status code to the end of the response payload.
3733 String s = Integer.toHexString(
3734 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3735 if (response.payload != null) {
3736 s = IccUtils.bytesToHexString(response.payload) + s;
3737 }
3738 return s;
3739 } finally {
3740 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003741 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003742 }
3743
3744 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003745 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003746 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3748 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003749
Malcolm Chend965c8b2018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 if (DBG) {
3753 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3754 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3755 }
3756
3757 IccIoResult response =
3758 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3759 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3760 subId);
3761
3762 if (DBG) {
3763 log("Exchange SIM_IO [R]" + response);
3764 }
3765
3766 byte[] result = null;
3767 int length = 2;
3768 if (response.payload != null) {
3769 length = 2 + response.payload.length;
3770 result = new byte[length];
3771 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3772 } else {
3773 result = new byte[length];
3774 }
3775
3776 result[length - 1] = (byte) response.sw2;
3777 result[length - 2] = (byte) response.sw1;
3778 return result;
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003781 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003782 }
3783
Nathan Haroldb3014052017-01-25 15:57:32 -08003784 /**
3785 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3786 * on a particular subscription
3787 */
sqianb6e41952018-03-12 14:54:01 -07003788 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3790 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3791 return null;
3792 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003793
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 if (appType != TelephonyManager.APPTYPE_USIM
3797 && appType != TelephonyManager.APPTYPE_SIM) {
3798 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3799 return null;
3800 }
3801 Object response = sendRequest(
3802 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3803 if (response instanceof String[]) {
3804 return (String[]) response;
3805 }
3806 // Response is an Exception of some kind,
3807 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003808 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 } finally {
3810 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003811 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003812 }
3813
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003815 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3817 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003818
Malcolm Chend965c8b2018-02-28 15:00:40 -08003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3822 if (response.payload == null) {
3823 return "";
3824 }
Evan Charltonc66da362014-05-16 14:06:40 -07003825
Malcolm Chend965c8b2018-02-28 15:00:40 -08003826 // Append the returned status code to the end of the response payload.
3827 String s = Integer.toHexString(
3828 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3829 s = IccUtils.bytesToHexString(response.payload) + s;
3830 return s;
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
Evan Charltonc66da362014-05-16 14:06:40 -07003834 }
3835
Jake Hambye994d462014-02-03 13:10:13 -08003836 /**
3837 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3838 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3839 *
3840 * @param itemID the ID of the item to read
3841 * @return the NV item as a String, or null on error.
3842 */
3843 @Override
3844 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3847 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848
3849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003852 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3854 return value;
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
Jake Hambye994d462014-02-03 13:10:13 -08003858 }
3859
3860 /**
3861 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3862 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3863 *
3864 * @param itemID the ID of the item to read
3865 * @param itemValue the value to write, as a String
3866 * @return true on success; false on any failure
3867 */
3868 @Override
3869 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003870 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3872 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873
3874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3877 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003878 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003879 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3880 return success;
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
Jake Hambye994d462014-02-03 13:10:13 -08003884 }
3885
3886 /**
3887 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3888 * Used for device configuration by some CDMA operators.
3889 *
3890 * @param preferredRoamingList byte array containing the new PRL
3891 * @return true on success; false on any failure
3892 */
3893 @Override
3894 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3896 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003897
3898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3901 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3902 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3903 return success;
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
3906 }
Jake Hambye994d462014-02-03 13:10:13 -08003907 }
3908
3909 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003910 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003911 * Used for device configuration by some CDMA operators.
3912 *
chen xu1cc0abe2018-10-26 17:39:23 -07003913 * @param slotIndex - device slot.
3914 *
Jake Hambye994d462014-02-03 13:10:13 -08003915 * @return true on success; false on any failure
3916 */
3917 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003918 public boolean resetModemConfig(int slotIndex) {
3919 Phone phone = PhoneFactory.getPhone(slotIndex);
3920 if (phone != null) {
3921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3922 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003923
chen xu1cc0abe2018-10-26 17:39:23 -07003924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3927 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3928 return success;
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003932 }
chen xu1cc0abe2018-10-26 17:39:23 -07003933 return false;
3934 }
3935
3936 /**
3937 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3938 *
3939 * @param slotIndex - device slot.
3940 *
3941 * @return true on success; false on any failure
3942 */
3943 @Override
3944 public boolean rebootModem(int slotIndex) {
3945 Phone phone = PhoneFactory.getPhone(slotIndex);
3946 if (phone != null) {
3947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3948 mApp, phone.getSubId(), "rebootModem");
3949
3950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3953 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3954 return success;
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003960 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003961
Svet Ganovb320e182015-04-16 12:30:10 -07003962 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003963 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003965 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003966 return new String[0];
3967 }
3968
Malcolm Chend965c8b2018-02-28 15:00:40 -08003969 final long identity = Binder.clearCallingIdentity();
3970 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003971 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
Wink Saville36469e72014-06-11 15:17:00 -07003975 }
3976
Brad Ebinger51f743a2017-01-23 13:50:20 -08003977 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003978 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3979 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003980 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003981 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003982 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 PhoneFactory.getImsResolver().enableIms(slotId);
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003990 }
3991
3992 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003993 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3994 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003995 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003996 public void disableIms(int slotId) {
3997 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003998
3999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 PhoneFactory.getImsResolver().disableIms(slotId);
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
4004 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004005 }
4006
4007 /**
4008 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4009 * feature or {@link null} if the service is not available. If the feature is available, the
4010 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4011 */
4012 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004013 IImsServiceFeatureCallback callback) {
4014 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004015
4016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004022 }
4023
4024 /**
4025 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4026 * feature during emergency calling or {@link null} if the service is not available. If the
4027 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4028 * listener for feature updates.
4029 */
4030 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4031 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004032
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4036 } finally {
4037 Binder.restoreCallingIdentity(identity);
4038 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004039 }
4040
Brad Ebinger5f64b052017-12-14 14:26:15 -08004041 /**
4042 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4043 * specified.
4044 */
4045 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4046 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004047
4048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004054 }
4055
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004056 /**
4057 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4058 * specified.
4059 */
4060 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4061 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004062
4063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004069 }
4070
Brad Ebinger884c07b2018-02-15 16:17:40 -08004071 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004072 * Sets the ImsService Package Name that Telephony will bind to.
4073 *
4074 * @param slotId the slot ID that the ImsService should bind for.
4075 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4076 * ImsService is the device default ImsService.
4077 * @param packageName The package name of the application that contains the ImsService to bind
4078 * to.
4079 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4080 * @hide
4081 */
4082 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004083 int[] subIds = SubscriptionManager.getSubId(slotId);
4084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4085 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4086 "setImsService");
4087
Malcolm Chend965c8b2018-02-28 15:00:40 -08004088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4091 isCarrierImsService, packageName);
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004095 }
4096
4097 /**
4098 * Return the ImsService configuration.
4099 *
4100 * @param slotId The slot that the ImsService is associated with.
4101 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4102 * the device default.
4103 * @return the package name of the ImsService configuration.
4104 */
4105 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004106 int[] subIds = SubscriptionManager.getSubId(slotId);
4107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4108 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4109 "getImsService");
4110
Malcolm Chend965c8b2018-02-28 15:00:40 -08004111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4114 isCarrierImsService);
4115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004118 }
4119
Wink Saville36469e72014-06-11 15:17:00 -07004120 public void setImsRegistrationState(boolean registered) {
4121 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004125 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Wink Saville36469e72014-06-11 15:17:00 -07004129 }
4130
4131 /**
Stuart Scott54788802015-03-30 13:18:01 -07004132 * Set the network selection mode to automatic.
4133 *
4134 */
4135 @Override
4136 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4138 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004139
Pengquan Meng466e2482018-09-21 15:54:48 -07004140 if (!isActiveSubscription(subId)) {
4141 return;
4142 }
4143
Malcolm Chend965c8b2018-02-28 15:00:40 -08004144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4147 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
Stuart Scott54788802015-03-30 13:18:01 -07004151 }
4152
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004153 /**
4154 * Ask the radio to connect to the input network and change selection mode to manual.
4155 *
4156 * @param subId the id of the subscription.
4157 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4158 * the operator to attach to.
4159 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4160 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4161 * normal network selection next time.
4162 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004163 */
4164 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004165 public boolean setNetworkSelectionModeManual(
4166 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4168 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004169
4170 if (!isActiveSubscription(subId)) {
4171 return false;
4172 }
4173
Malcolm Chend965c8b2018-02-28 15:00:40 -08004174 final long identity = Binder.clearCallingIdentity();
4175 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004176 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004177 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004178 if (DBG) {
4179 log("setNetworkSelectionModeManual: subId: " + subId
4180 + " operator: " + operatorInfo);
4181 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004182 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004186 }
4187
4188 /**
4189 * Scans for available networks.
4190 */
4191 @Override
4192 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4194 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004195
Pengquan Meng0c05b502018-09-06 09:59:22 -07004196 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004197 try {
4198 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004199 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004200 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004201 } finally {
4202 Binder.restoreCallingIdentity(identity);
4203 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004204 }
4205
4206 /**
yinxub1bed742017-04-17 11:45:04 -07004207 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004208 *
yinxub1bed742017-04-17 11:45:04 -07004209 * @param subId id of the subscription
4210 * @param request contains the radio access networks with bands/channels to scan
4211 * @param messenger callback messenger for scan results or errors
4212 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004213 * @return the id of the requested scan which can be used to stop the scan.
4214 */
4215 @Override
4216 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4217 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4219 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004220
4221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 return mNetworkScanRequestTracker.startNetworkScan(
4224 request, messenger, binder, getPhone(subId));
4225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
yinxu504e1392017-04-12 16:03:22 -07004228 }
4229
4230 /**
4231 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004232 *
4233 * @param subId id of the subscription
4234 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004235 */
4236 @Override
4237 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4239 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
yinxu504e1392017-04-12 16:03:22 -07004247 }
4248
4249 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004250 * Get the calculated preferred network type.
4251 * Used for debugging incorrect network type.
4252 *
4253 * @return the preferred network type, defined in RILConstants.java.
4254 */
4255 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004256 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004257 final Phone defaultPhone = getDefaultPhone();
4258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4259 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004260 return RILConstants.PREFERRED_NETWORK_MODE;
4261 }
4262
Malcolm Chend965c8b2018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004266 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
Junda Liu84d15a22014-07-02 11:21:04 -07004270 }
4271
4272 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004273 * Get the preferred network type.
4274 * Used for device configuration by some CDMA operators.
4275 *
4276 * @return the preferred network type, defined in RILConstants.java.
4277 */
4278 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004279 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004280 TelephonyPermissions
4281 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4282 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 if (DBG) log("getPreferredNetworkType");
4287 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4288 int networkType = (result != null ? result[0] : -1);
4289 if (DBG) log("getPreferredNetworkType: " + networkType);
4290 return networkType;
4291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004294 }
4295
4296 /**
4297 * Set the preferred network type.
4298 * Used for device configuration by some CDMA operators.
4299 *
4300 * @param networkType the preferred network type, defined in RILConstants.java.
4301 * @return true on success; false on any failure.
4302 */
4303 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004304 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4306 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4311 Boolean success = (Boolean) sendRequest(
4312 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4313 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4314 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004315 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004316 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4317 }
4318 return success;
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004321 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004322 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004323
4324 /**
Junda Liu475951f2014-11-07 16:45:03 -08004325 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004326 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004327 * tethering.
4328 *
4329 * @return 0: Not required. 1: required. 2: Not set.
4330 * @hide
4331 */
4332 @Override
4333 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004334 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004335
4336 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004337 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004338 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004339 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004341 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004342 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004343 dunRequired = 1;
4344 }
4345 return dunRequired;
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004348 }
Junda Liu475951f2014-11-07 16:45:03 -08004349 }
4350
4351 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004352 * Set mobile data enabled
4353 * Used by the user through settings etc to turn on/off mobile data
4354 *
4355 * @param enable {@code true} turn turn data on, else {@code false}
4356 */
4357 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004358 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004361
4362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 int phoneId = mSubscriptionController.getPhoneId(subId);
4365 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4366 Phone phone = PhoneFactory.getPhone(phoneId);
4367 if (phone != null) {
4368 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004369 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004370 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004371 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004372 }
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004375 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004376 }
4377
4378 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004379 * Get the user enabled state of Mobile Data.
4380 *
4381 * TODO: remove and use isUserDataEnabled.
4382 * This can't be removed now because some vendor codes
4383 * calls through ITelephony directly while they should
4384 * use TelephonyManager.
4385 *
4386 * @return true on enabled
4387 */
4388 @Override
4389 public boolean getDataEnabled(int subId) {
4390 return isUserDataEnabled(subId);
4391 }
4392
4393 /**
4394 * Get whether mobile data is enabled per user setting.
4395 *
4396 * There are other factors deciding whether mobile data is actually enabled, but they are
4397 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004398 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004399 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004400 *
4401 * @return {@code true} if data is enabled else {@code false}
4402 */
4403 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004404 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004405 try {
4406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4407 null);
4408 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4410 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004411 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004412
4413 final long identity = Binder.clearCallingIdentity();
4414 try {
4415 int phoneId = mSubscriptionController.getPhoneId(subId);
4416 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4417 Phone phone = PhoneFactory.getPhone(phoneId);
4418 if (phone != null) {
4419 boolean retVal = phone.isUserDataEnabled();
4420 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4421 return retVal;
4422 } else {
4423 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4424 return false;
4425 }
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004428 }
4429 }
4430
4431 /**
4432 * Get whether mobile data is enabled.
4433 *
4434 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4435 * whether mobile data is actually enabled.
4436 *
4437 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4438 *
4439 * @return {@code true} if data is enabled else {@code false}
4440 */
4441 @Override
4442 public boolean isDataEnabled(int subId) {
4443 try {
4444 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4445 null);
4446 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4448 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004449 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004450
4451 final long identity = Binder.clearCallingIdentity();
4452 try {
4453 int phoneId = mSubscriptionController.getPhoneId(subId);
4454 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4455 Phone phone = PhoneFactory.getPhone(phoneId);
4456 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004457 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004458 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4459 return retVal;
4460 } else {
4461 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4462 return false;
4463 }
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004466 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004467 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004468
4469 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004470 public int getCarrierPrivilegeStatus(int subId) {
4471 final Phone phone = getPhone(subId);
4472 if (phone == null) {
4473 loge("getCarrierPrivilegeStatus: Invalid subId");
4474 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4475 }
4476 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004477 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004478 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004479 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4480 }
4481 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004482 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004483 }
Junda Liu29340342014-07-10 15:23:27 -07004484
4485 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004486 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4487 final Phone phone = getPhone(subId);
4488 if (phone == null) {
4489 loge("getCarrierPrivilegeStatus: Invalid subId");
4490 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4491 }
4492 UiccProfile profile =
4493 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4494 if (profile == null) {
4495 loge("getCarrierPrivilegeStatus: No UICC");
4496 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4497 }
4498 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4499 }
4500
4501 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004502 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004503 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004504 if (TextUtils.isEmpty(pkgName))
4505 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004506 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004507 if (card == null) {
4508 loge("checkCarrierPrivilegesForPackage: No UICC");
4509 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4510 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004511 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4512 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004513 }
4514
4515 @Override
4516 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004517 if (TextUtils.isEmpty(pkgName))
4518 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004519 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4521 UiccCard card = UiccController.getInstance().getUiccCard(i);
4522 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004523 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004524 continue;
4525 }
4526
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004527 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004528 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4529 break;
4530 }
4531 }
4532
4533 return result;
Junda Liu29340342014-07-10 15:23:27 -07004534 }
Derek Tan89e89d42014-07-08 17:00:10 -07004535
4536 @Override
Junda Liue64de782015-04-16 17:19:16 -07004537 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4538 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4539 loge("phoneId " + phoneId + " is not valid.");
4540 return null;
4541 }
4542 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004543 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004544 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004545 return null ;
4546 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004547 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004548 }
4549
Amith Yamasani6e118872016-02-19 12:53:51 -08004550 @Override
4551 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004552 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004553 List<String> privilegedPackages = new ArrayList<>();
4554 List<PackageInfo> packages = null;
4555 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4556 UiccCard card = UiccController.getInstance().getUiccCard(i);
4557 if (card == null) {
4558 // No UICC in that slot.
4559 continue;
4560 }
4561 if (card.hasCarrierPrivilegeRules()) {
4562 if (packages == null) {
4563 // Only check packages in user 0 for now
4564 packages = pm.getInstalledPackagesAsUser(
4565 PackageManager.MATCH_DISABLED_COMPONENTS
4566 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4567 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4568 }
4569 for (int p = packages.size() - 1; p >= 0; p--) {
4570 PackageInfo pkgInfo = packages.get(p);
4571 if (pkgInfo != null && pkgInfo.packageName != null
4572 && card.getCarrierPrivilegeStatus(pkgInfo)
4573 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4574 privilegedPackages.add(pkgInfo.packageName);
4575 }
4576 }
4577 }
4578 }
4579 return privilegedPackages;
4580 }
4581
Wink Savilleb564aae2014-10-23 10:18:09 -07004582 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004583 final Phone phone = getPhone(subId);
4584 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004585 if (card == null) {
4586 loge("getIccId: No UICC");
4587 return null;
4588 }
4589 String iccId = card.getIccId();
4590 if (TextUtils.isEmpty(iccId)) {
4591 loge("getIccId: ICC ID is null or empty.");
4592 return null;
4593 }
4594 return iccId;
4595 }
4596
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004597 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004598 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4599 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004600 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4601 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004602
Malcolm Chend965c8b2018-02-28 15:00:40 -08004603 final long identity = Binder.clearCallingIdentity();
4604 try {
4605 final String iccId = getIccId(subId);
4606 final Phone phone = getPhone(subId);
4607 if (phone == null) {
4608 return false;
4609 }
4610 final String subscriberId = phone.getSubscriberId();
4611
4612 if (DBG_MERGE) {
4613 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4614 + subscriberId + " to " + number);
4615 }
4616
4617 if (TextUtils.isEmpty(iccId)) {
4618 return false;
4619 }
4620
4621 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4622
4623 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4624 if (alphaTag == null) {
4625 editor.remove(alphaTagPrefKey);
4626 } else {
4627 editor.putString(alphaTagPrefKey, alphaTag);
4628 }
4629
4630 // Record both the line number and IMSI for this ICCID, since we need to
4631 // track all merged IMSIs based on line number
4632 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4633 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4634 if (number == null) {
4635 editor.remove(numberPrefKey);
4636 editor.remove(subscriberPrefKey);
4637 } else {
4638 editor.putString(numberPrefKey, number);
4639 editor.putString(subscriberPrefKey, subscriberId);
4640 }
4641
4642 editor.commit();
4643 return true;
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004646 }
Derek Tan7226c842014-07-02 17:42:23 -07004647 }
4648
4649 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004650 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004651 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004653 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004654 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004655 return null;
4656 }
Derek Tan97ebb422014-09-05 16:55:38 -07004657
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 String iccId = getIccId(subId);
4661 if (iccId != null) {
4662 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4663 if (DBG_MERGE) {
4664 log("getLine1NumberForDisplay returning "
4665 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4666 }
4667 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004668 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004669 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4670 return null;
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004673 }
Derek Tan7226c842014-07-02 17:42:23 -07004674 }
4675
4676 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004677 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004679 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004680 return null;
4681 }
Derek Tan97ebb422014-09-05 16:55:38 -07004682
Malcolm Chend965c8b2018-02-28 15:00:40 -08004683 final long identity = Binder.clearCallingIdentity();
4684 try {
4685 String iccId = getIccId(subId);
4686 if (iccId != null) {
4687 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4688 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4689 }
4690 return null;
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004693 }
Derek Tan7226c842014-07-02 17:42:23 -07004694 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004695
4696 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004697 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004698 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4699 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004701 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4702 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004703 return null;
4704 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004705
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004706 final long identity = Binder.clearCallingIdentity();
4707 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004708 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004709 final TelephonyManager tele = TelephonyManager.from(context);
4710 final SubscriptionManager sub = SubscriptionManager.from(context);
4711
4712 // Figure out what subscribers are currently active
4713 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4714 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4715 // the process, where TelephonyManager was instantiated.
4716 // Otherwise AppOps check will fail.
4717
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004718 final int[] subIds = sub.getActiveSubscriptionIdList();
4719 for (int subId : subIds) {
4720 activeSubscriberIds.add(tele.getSubscriberId(subId));
4721 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004722
4723 // First pass, find a number override for an active subscriber
4724 String mergeNumber = null;
4725 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4726 for (String key : prefs.keySet()) {
4727 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4728 final String subscriberId = (String) prefs.get(key);
4729 if (activeSubscriberIds.contains(subscriberId)) {
4730 final String iccId = key.substring(
4731 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4732 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4733 mergeNumber = (String) prefs.get(numberKey);
4734 if (DBG_MERGE) {
4735 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4736 + " for active subscriber " + subscriberId);
4737 }
4738 if (!TextUtils.isEmpty(mergeNumber)) {
4739 break;
4740 }
4741 }
4742 }
4743 }
4744
4745 // Shortcut when no active merged subscribers
4746 if (TextUtils.isEmpty(mergeNumber)) {
4747 return null;
4748 }
4749
4750 // Second pass, find all subscribers under that line override
4751 final ArraySet<String> result = new ArraySet<>();
4752 for (String key : prefs.keySet()) {
4753 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4754 final String number = (String) prefs.get(key);
4755 if (mergeNumber.equals(number)) {
4756 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4757 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4758 final String subscriberId = (String) prefs.get(subscriberKey);
4759 if (!TextUtils.isEmpty(subscriberId)) {
4760 result.add(subscriberId);
4761 }
4762 }
4763 }
4764 }
4765
4766 final String[] resultArray = result.toArray(new String[result.size()]);
4767 Arrays.sort(resultArray);
4768 if (DBG_MERGE) {
4769 Slog.d(LOG_TAG,
4770 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4771 }
4772 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004773 } finally {
4774 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004775 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004776 }
4777
4778 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004779 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004780 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4781 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004782
4783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 final Phone phone = getPhone(subId);
4786 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004790 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004791
4792 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004793 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004794 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4795 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004797
4798 final long identity = Binder.clearCallingIdentity();
4799 try {
4800 final Phone phone = getPhone(subId);
4801 if (phone == null) {
4802 return false;
4803 }
4804 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4805 cdmaNonRoamingList);
4806 } finally {
4807 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004808 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004809 }
4810
4811 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004812 @Deprecated
4813 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4814 enforceModifyPermission();
4815
4816 int returnValue = 0;
4817 try {
vagdevie435a3e2018-08-15 16:01:53 -07004818 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004819 if(result.exception == null) {
4820 if (result.result != null) {
4821 byte[] responseData = (byte[])(result.result);
4822 if(responseData.length > oemResp.length) {
4823 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4824 responseData.length + "bytes. Buffer Size is " +
4825 oemResp.length + "bytes.");
4826 }
4827 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4828 returnValue = responseData.length;
4829 }
4830 } else {
4831 CommandException ex = (CommandException) result.exception;
4832 returnValue = ex.getCommandError().ordinal();
4833 if(returnValue > 0) returnValue *= -1;
4834 }
4835 } catch (RuntimeException e) {
4836 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4837 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4838 if(returnValue > 0) returnValue *= -1;
4839 }
4840
4841 return returnValue;
4842 }
4843
4844 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004845 public void setRadioCapability(RadioAccessFamily[] rafs) {
4846 try {
4847 ProxyController.getInstance().setRadioCapability(rafs);
4848 } catch (RuntimeException e) {
4849 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4850 }
4851 }
4852
4853 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004854 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004855 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004856 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004857 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004858 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004859 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004860 final long identity = Binder.clearCallingIdentity();
4861 try {
chen xufeeed752018-10-26 14:17:57 -07004862 TelephonyPermissions
4863 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4864 mApp, phone.getSubId(), "getRadioAccessFamily");
4865 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
chen xufeeed752018-10-26 14:17:57 -07004869 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004870 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004871
4872 @Override
4873 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004874 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004875 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004876
4877 final long identity = Binder.clearCallingIdentity();
4878 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004879 ImsManager.getInstance(defaultPhone.getContext(),
4880 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004884 }
4885
4886 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004887 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004888 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004890 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004891 return false;
4892 }
Svet Ganovb320e182015-04-16 12:30:10 -07004893
Malcolm Chend965c8b2018-02-28 15:00:40 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 // Check the user preference and the system-level IMS setting. Even if the user has
4897 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4898 // In the long run, we may instead need to check if there exists a connection service
4899 // which can support video calling.
4900 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004901 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004902 return imsManager.isVtEnabledByPlatform()
4903 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4904 && imsManager.isVtEnabledByUser();
4905 } finally {
4906 Binder.restoreCallingIdentity(identity);
4907 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004908 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004909
Andrew Leea1239f22015-03-02 17:44:07 -08004910 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004911 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4913 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4914 return false;
4915 }
4916
4917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 CarrierConfigManager configManager =
4920 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004921 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004922 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4923 } finally {
4924 Binder.restoreCallingIdentity(identity);
4925 }
Andrew Leea1239f22015-03-02 17:44:07 -08004926 }
4927
4928 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004929 public boolean isWorldPhone(int subId, String callingPackage) {
4930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4931 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4932 return false;
4933 }
4934
4935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 CarrierConfigManager configManager =
4938 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004939 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004940 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
Andrew Leea1239f22015-03-02 17:44:07 -08004944 }
4945
Andrew Lee9431b832015-03-09 18:46:45 -07004946 @Override
4947 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004948 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004949 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004950 }
4951
4952 @Override
4953 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004956 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Andrew Lee9431b832015-03-09 18:46:45 -07004960 }
4961
Hall Liuf6668912018-10-31 17:05:23 -07004962 /**
4963 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4964 * support for the feature and device firmware support.
4965 *
4966 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4967 */
4968 @Override
4969 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004971 final Phone phone = getPhone(subscriptionId);
4972 if (phone == null) {
4973 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4974 return false;
4975 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004976 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004977 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004978 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4979 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004980 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004981 return isCarrierSupported && isDeviceSupported;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
Hall Liu98187582018-01-22 19:15:32 -08004985 }
4986
Hall Liuf6668912018-10-31 17:05:23 -07004987 /**
4988 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4989 * both also support RTT.
4990 */
4991 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Hall Liuf6668912018-10-31 17:05:23 -07004994 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004995 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004999 }
5000
Sanket Padawe7310cc72015-01-14 09:53:20 -08005001 /**
5002 * Returns the unique device ID of phone, for example, the IMEI for
5003 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5004 *
5005 * <p>Requires Permission:
5006 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5007 */
5008 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005009 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005010 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005011 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005012 return null;
5013 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005014 int subId = phone.getSubId();
5015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5016 mApp, subId, callingPackage, "getDeviceId")) {
5017 return null;
5018 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005019
5020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 return phone.getDeviceId();
5023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005026 }
5027
Ping Sunc67b7c22016-03-02 19:16:45 +08005028 /**
5029 * {@hide}
5030 * Returns the IMS Registration Status on a particular subid
5031 *
5032 * @param subId
5033 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005034 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005035 Phone phone = getPhone(subId);
5036 if (phone != null) {
5037 return phone.isImsRegistered();
5038 } else {
5039 return false;
5040 }
5041 }
5042
Santos Cordon7a1885b2015-02-03 11:15:19 -08005043 @Override
5044 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005051 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005052
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005053 /**
5054 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005055 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005056 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 Phone phone = getPhone(subId);
5060 if (phone != null) {
5061 return phone.isWifiCallingEnabled();
5062 } else {
5063 return false;
5064 }
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005067 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005068 }
5069
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005070 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005071 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005072 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005073 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 Phone phone = getPhone(subId);
5077 if (phone != null) {
5078 return phone.isVideoEnabled();
5079 } else {
5080 return false;
5081 }
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005084 }
5085 }
5086
5087 /**
5088 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5089 * defined in {@link ImsRegistrationImplBase}.
5090 */
5091 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
5094 Phone phone = getPhone(subId);
5095 if (phone != null) {
5096 return phone.getImsRegistrationTech();
5097 } else {
5098 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5099 }
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005102 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005103 }
5104
Stuart Scott8eef64f2015-04-08 15:13:54 -07005105 @Override
5106 public void factoryReset(int subId) {
5107 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005108 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5109 return;
5110 }
5111
Svet Ganovcc087f82015-05-12 20:35:54 -07005112 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005113
Svet Ganovcc087f82015-05-12 20:35:54 -07005114 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005115 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5116 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005117 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005118 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005119 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005120 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5121 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005122 }
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005125 }
5126 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005127
5128 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005129 public String getSimLocaleForSubscriber(int subId) {
5130 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5131 final Phone phone = getPhone(subId);
5132 if (phone == null) {
5133 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005134 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005135 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005136 final long identity = Binder.clearCallingIdentity();
5137 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005138 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5139 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140 // Try and fetch the locale from the carrier properties or from the SIM language
5141 // preferences (EF-PL and EF-LI)...
5142 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005144 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5145 if (localeFromDefaultSim != null) {
5146 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5147 if (DBG) log("Using locale from subId: " + subId + " locale: "
5148 + localeFromDefaultSim);
5149 return localeFromDefaultSim.toLanguageTag();
5150 } else {
5151 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005152 }
5153 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005154
Malcolm Chend965c8b2018-02-28 15:00:40 -08005155 // The SIM language preferences only store a language (e.g. fr = French), not an
5156 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5157 // the SIM and carrier preferences does not include a country we add the country
5158 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005159 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005160 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005161 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005162 return mccLocale.toLanguageTag();
5163 }
5164
5165 if (DBG) log("No locale found - returning null");
5166 return null;
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005170 }
5171
5172 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005173 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005174 }
5175
Malcolm Chend965c8b2018-02-28 15:00:40 -08005176 /**
5177 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5178 */
5179 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005180 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005181 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005182
Chenjie Yu1ba97252018-01-11 18:16:20 -08005183 private final ModemActivityInfo mLastModemActivityInfo =
5184 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5185
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005186 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005187 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5188 * representing the state of the modem.
5189 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005190 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5191 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005192 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005193 */
5194 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005195 public void requestModemActivityInfo(ResultReceiver result) {
5196 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005197 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005198
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 ModemActivityInfo ret = null;
5202 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005203 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5204 CMD_GET_MODEM_ACTIVITY_INFO,
5205 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005206 if (isModemActivityInfoValid(info)) {
5207 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5208 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5209 mergedTxTimeMs[i] =
5210 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5211 }
5212 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5213 mLastModemActivityInfo.setSleepTimeMillis(
5214 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5215 mLastModemActivityInfo.setIdleTimeMillis(
5216 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5217 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5218 mLastModemActivityInfo.setRxTimeMillis(
5219 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5220 mLastModemActivityInfo.setEnergyUsed(
5221 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005222 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005223 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5224 mLastModemActivityInfo.getSleepTimeMillis(),
5225 mLastModemActivityInfo.getIdleTimeMillis(),
5226 mLastModemActivityInfo.getTxTimeMillis(),
5227 mLastModemActivityInfo.getRxTimeMillis(),
5228 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005229 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005230 Bundle bundle = new Bundle();
5231 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5232 result.send(0, bundle);
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005235 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005236 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005237
Siddharth Rayf5d29552018-06-17 15:02:38 -07005238 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5239 // less than total activity duration.
5240 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5241 if (info == null) {
5242 return false;
5243 }
5244 int activityDurationMs =
5245 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5246 int totalTxTimeMs = 0;
5247 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5248 totalTxTimeMs += info.getTxTimeMillis()[i];
5249 }
5250 return (info.isValid()
5251 && (info.getSleepTimeMillis() <= activityDurationMs)
5252 && (info.getIdleTimeMillis() <= activityDurationMs)
5253 && (info.getRxTimeMillis() <= activityDurationMs)
5254 && (totalTxTimeMs <= activityDurationMs));
5255 }
5256
Jack Yu85bd38a2015-11-09 11:34:32 -08005257 /**
5258 * {@hide}
5259 * Returns the service state information on specified subscription.
5260 */
5261 @Override
5262 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005264 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005265 return null;
5266 }
5267
Malcolm Chend965c8b2018-02-28 15:00:40 -08005268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 final Phone phone = getPhone(subId);
5271 if (phone == null) {
5272 return null;
5273 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005274
Malcolm Chend965c8b2018-02-28 15:00:40 -08005275 return phone.getServiceState();
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005279 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005280
5281 /**
5282 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5283 *
5284 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5285 * voicemail ringtone.
5286 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5287 * PhoneAccount.
5288 */
5289 @Override
5290 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5294 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005295 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005296 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005297
Malcolm Chend965c8b2018-02-28 15:00:40 -08005298 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005302 }
5303
5304 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005305 * Sets the per-account voicemail ringtone.
5306 *
5307 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5308 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5309 *
5310 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5311 * voicemail ringtone.
5312 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5313 * PhoneAccount.
5314 */
5315 @Override
5316 public void setVoicemailRingtoneUri(String callingPackage,
5317 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005318 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5320 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005321 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5323 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5324 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005325 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005326
5327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5330 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005331 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005332 }
5333 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005336 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005337 }
5338
5339 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005340 * Returns whether vibration is set for voicemail notification in Phone settings.
5341 *
5342 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5343 * voicemail vibration setting.
5344 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5345 */
5346 @Override
5347 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5351 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005352 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005353 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005354
Malcolm Chend965c8b2018-02-28 15:00:40 -08005355 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005359 }
5360
Youhan Wange64578a2016-05-02 15:32:42 -07005361 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005362 * Sets the per-account voicemail vibration.
5363 *
5364 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5365 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5366 *
5367 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5368 * voicemail vibration setting.
5369 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5370 * specific PhoneAccount.
5371 */
5372 @Override
5373 public void setVoicemailVibrationEnabled(String callingPackage,
5374 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005375 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5377 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005378 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5380 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5381 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005382 }
5383
Malcolm Chend965c8b2018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5387 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005388 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005389 }
5390 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005393 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005394 }
5395
5396 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005397 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5398 *
5399 * @throws SecurityException if the caller does not have the required permission
5400 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005401 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005403 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005404 }
5405
5406 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005407 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5408 * permission.
5409 *
5410 * @throws SecurityException if the caller does not have the required permission
5411 */
5412 private void enforceSendSmsPermission() {
5413 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5414 }
5415
5416 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005417 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005418 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005419 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005420 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005421 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005425 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005426 if (componentName == null) {
5427 throw new SecurityException(
5428 "Caller not current active visual voicemail package[null]");
5429 }
5430 String vvmPackage = componentName.getPackageName();
5431 if (!callingPackage.equals(vvmPackage)) {
5432 throw new SecurityException("Caller not current active visual voicemail package["
5433 + vvmPackage + "]");
5434 }
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005437 }
5438 }
5439
5440 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005441 * Return the application ID for the app type.
5442 *
5443 * @param subId the subscription ID that this request applies to.
5444 * @param appType the uicc app type.
5445 * @return Application ID for specificied app type, or null if no uicc.
5446 */
5447 @Override
5448 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005449 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005450 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005451
5452 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005453 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005454 if (phone == null) {
5455 return null;
5456 }
5457 String aid = null;
5458 try {
5459 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5460 .getApplicationByType(appType).getAid();
5461 } catch (Exception e) {
5462 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5463 }
5464 return aid;
5465 } finally {
5466 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005467 }
Youhan Wange64578a2016-05-02 15:32:42 -07005468 }
5469
Youhan Wang4001d252016-05-11 10:29:41 -07005470 /**
5471 * Return the Electronic Serial Number.
5472 *
5473 * @param subId the subscription ID that this request applies to.
5474 * @return ESN or null if error.
5475 */
5476 @Override
5477 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005478 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005479 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480
5481 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005482 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005483 if (phone == null) {
5484 return null;
5485 }
5486 String esn = null;
5487 try {
5488 esn = phone.getEsn();
5489 } catch (Exception e) {
5490 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5491 }
5492 return esn;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005495 }
Youhan Wang4001d252016-05-11 10:29:41 -07005496 }
5497
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005498 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005499 * Return the Preferred Roaming List Version.
5500 *
5501 * @param subId the subscription ID that this request applies to.
5502 * @return PRLVersion or null if error.
5503 */
5504 @Override
5505 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005506 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005507 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005510 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005511 if (phone == null) {
5512 return null;
5513 }
5514 String cdmaPrlVersion = null;
5515 try {
5516 cdmaPrlVersion = phone.getCdmaPrlVersion();
5517 } catch (Exception e) {
5518 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5519 }
5520 return cdmaPrlVersion;
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005523 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005524 }
5525
5526 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005527 * Get snapshot of Telephony histograms
5528 * @return List of Telephony histograms
5529 * @hide
5530 */
5531 @Override
5532 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5534 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005535
5536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 return RIL.getTelephonyRILTimingHistograms();
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005542 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005543
5544 /**
5545 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005546 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5547 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005548 * Require system privileges. In the future we may add this to carrier APIs.
5549 *
Michele Berionne0963c862018-11-27 18:57:59 -08005550 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005551 */
5552 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005553 @TelephonyManager.SetCarrierRestrictionResult
5554 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005555 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005557
Michele Berionne0963c862018-11-27 18:57:59 -08005558 if (carrierRestrictionRules == null) {
5559 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005560 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005561
Malcolm Chend965c8b2018-02-28 15:00:40 -08005562 final long identity = Binder.clearCallingIdentity();
5563 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005564 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005565 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005569 }
5570
5571 /**
5572 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005573 * Get the allowed carrier list and the excluded carrier list, including the priority between
5574 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005575 * Require system privileges. In the future we may add this to carrier APIs.
5576 *
Michele Berionne0963c862018-11-27 18:57:59 -08005577 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005578 */
5579 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005580 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005581 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005583
5584 final long identity = Binder.clearCallingIdentity();
5585 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005586 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5587 if (response instanceof CarrierRestrictionRules) {
5588 return (CarrierRestrictionRules) response;
5589 }
5590 // Response is an Exception of some kind,
5591 // which is signalled to the user as a NULL retval
5592 return null;
5593 } catch (Exception e) {
5594 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5595 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005599 }
5600
fionaxu59545b42016-05-25 15:53:37 -07005601 /**
5602 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5603 * @param subId the subscription ID that this action applies to.
5604 * @param enabled control enable or disable metered apns.
5605 * {@hide}
5606 */
5607 @Override
5608 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5609 enforceModifyPermission();
5610 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005611
5612 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005613 if (phone == null) {
5614 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5615 return;
5616 }
5617 try {
5618 phone.carrierActionSetMeteredApnsEnabled(enabled);
5619 } catch (Exception e) {
5620 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005623 }
5624 }
5625
5626 /**
5627 * Action set from carrier signalling broadcast receivers to enable/disable radio
5628 * @param subId the subscription ID that this action applies to.
5629 * @param enabled control enable or disable radio.
5630 * {@hide}
5631 */
5632 @Override
5633 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5634 enforceModifyPermission();
5635 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005638 if (phone == null) {
5639 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5640 return;
5641 }
5642 try {
5643 phone.carrierActionSetRadioEnabled(enabled);
5644 } catch (Exception e) {
5645 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005648 }
5649 }
5650
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005651 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005652 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5653 * network status based on which carrier apps could apply actions accordingly,
5654 * enable/disable default url handler for example.
5655 *
5656 * @param subId the subscription ID that this action applies to.
5657 * @param report control start/stop reporting the default network status.
5658 * {@hide}
5659 */
5660 @Override
5661 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5662 enforceModifyPermission();
5663 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005664
5665 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005666 if (phone == null) {
5667 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5668 return;
5669 }
5670 try {
5671 phone.carrierActionReportDefaultNetworkStatus(report);
5672 } catch (Exception e) {
5673 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005676 }
5677 }
5678
5679 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005680 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5681 * bug report is being generated.
5682 */
5683 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005684 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005685 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5686 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005687 writer.println("Permission Denial: can't dump Phone from pid="
5688 + Binder.getCallingPid()
5689 + ", uid=" + Binder.getCallingUid()
5690 + "without permission "
5691 + android.Manifest.permission.DUMP);
5692 return;
5693 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005694 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005695 }
Jack Yueb89b242016-06-22 13:27:47 -07005696
Brad Ebingerdac2f002018-04-03 15:17:52 -07005697 @Override
5698 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5699 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5700 throws RemoteException {
5701 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5702 }
5703
Jack Yueb89b242016-06-22 13:27:47 -07005704 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005705 * Get aggregated video call data usage since boot.
5706 *
5707 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5708 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005709 * {@hide}
5710 */
5711 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005712 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5714 null);
5715
Malcolm Chend965c8b2018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 // NetworkStatsService keeps tracking the active network interface and identity. It
5719 // records the delta with the corresponding network identity.
5720 // We just return the total video call data usage snapshot since boot.
5721 Phone phone = getPhone(subId);
5722 if (phone != null) {
5723 return phone.getVtDataUsage(perUidStats);
5724 }
5725 return null;
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005728 }
Jack Yueb89b242016-06-22 13:27:47 -07005729 }
Jack Yu75ab2952016-07-08 14:29:33 -07005730
5731 /**
5732 * Policy control of data connection. Usually used when data limit is passed.
5733 * @param enabled True if enabling the data, otherwise disabling.
5734 * @param subId Subscription index
5735 * {@hide}
5736 */
5737 @Override
5738 public void setPolicyDataEnabled(boolean enabled, int subId) {
5739 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 Phone phone = getPhone(subId);
5744 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005745 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005746 }
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005749 }
5750 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005751
5752 /**
5753 * Get Client request stats
5754 * @return List of Client Request Stats
5755 * @hide
5756 */
5757 @Override
5758 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005760 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005761 return null;
5762 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005763 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005764
Malcolm Chend965c8b2018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 if (phone != null) {
5768 return phone.getClientRequestStats();
5769 }
5770
5771 return null;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005775 }
5776
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005777 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005778 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005779 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005780 }
Jack Yueb4124c2017-02-16 15:32:43 -08005781
5782 /**
Grace Chen70990072017-03-24 17:21:30 -07005783 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005784 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005785 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005786 * @param state State of SIM (power down, power up, pass through)
5787 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5788 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5789 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005790 *
5791 **/
5792 @Override
Grace Chen70990072017-03-24 17:21:30 -07005793 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005794 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005795 Phone phone = PhoneFactory.getPhone(slotIndex);
5796
vagdevie435a3e2018-08-15 16:01:53 -07005797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5798
Malcolm Chend965c8b2018-02-28 15:00:40 -08005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005802 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005803 }
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005806 }
5807 }
Shuo Qiandd210312017-04-12 22:11:33 +00005808
Tyler Gunn65d45c22017-06-05 11:22:26 -07005809 private boolean isUssdApiAllowed(int subId) {
5810 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005811 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005812 if (configManager == null) {
5813 return false;
5814 }
5815 PersistableBundle pb = configManager.getConfigForSubId(subId);
5816 if (pb == null) {
5817 return false;
5818 }
5819 return pb.getBoolean(
5820 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5821 }
5822
Shuo Qiandd210312017-04-12 22:11:33 +00005823 /**
5824 * Check if phone is in emergency callback mode
5825 * @return true if phone is in emergency callback mode
5826 * @param subId sub id
5827 */
goneil9c5f4872017-12-05 14:07:56 -08005828 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005829 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005830 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005831 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 if (phone != null) {
5836 return phone.isInEcm();
5837 } else {
5838 return false;
5839 }
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005842 }
5843 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005844
5845 /**
5846 * Get the current signal strength information for the given subscription.
5847 * Because this information is not updated when the device is in a low power state
5848 * it should not be relied-upon to be current.
5849 * @param subId Subscription index
5850 * @return the most recent cached signal strength info from the modem
5851 */
5852 @Override
5853 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 Phone p = getPhone(subId);
5857 if (p == null) {
5858 return null;
5859 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005860
Malcolm Chend965c8b2018-02-28 15:00:40 -08005861 return p.getSignalStrength();
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005865 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005866
Pengquan Meng9140aec2018-08-22 14:49:57 -07005867 /**
chen xu907e5a22018-10-11 13:21:04 -07005868 * Get the current modem radio state for the given slot.
5869 * @param slotIndex slot index.
5870 * @param callingPackage the name of the package making the call.
5871 * @return the current radio power state from the modem
5872 */
5873 @Override
5874 public int getRadioPowerState(int slotIndex, String callingPackage) {
5875 Phone phone = PhoneFactory.getPhone(slotIndex);
5876 if (phone != null) {
5877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5878 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5879 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5880 }
5881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 return phone.getRadioPowerState();
5885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
5888 }
5889 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5890 }
5891
5892 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005893 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5894 *
5895 * <p>Requires one of the following permissions:
5896 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5897 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5898 * privileges.
5899 *
5900 * @param subId subscription id
5901 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5902 * {@code false}.
5903 */
5904 @Override
5905 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005906 boolean isEnabled = false;
5907 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005908 try {
5909 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005910 null /* message */);
5911 Phone phone = getPhone(subId);
5912 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005913 } catch (Exception e) {
5914 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5915 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005916 } finally {
5917 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005918 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005919 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005920 }
5921
5922
5923 /**
5924 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5925 *
5926 * <p> Requires permission:
5927 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5928 * privileges.
5929 *
5930 * @param subId subscription id
5931 * @param isEnabled {@code true} means enable, {@code false} means disable.
5932 */
5933 @Override
5934 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5938 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005939
Pengquan Meng0c05b502018-09-06 09:59:22 -07005940 Phone phone = getPhone(subId);
5941 if (phone != null) {
5942 phone.setDataRoamingEnabled(isEnabled);
5943 }
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005946 }
5947 }
5948
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005949 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005950 public boolean isManualNetworkSelectionAllowed(int subId) {
5951 boolean isAllowed = true;
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5955 mApp, subId, "isManualNetworkSelectionAllowed");
5956 Phone phone = getPhone(subId);
5957 if (phone != null) {
5958 isAllowed = phone.isCspPlmnEnabled();
5959 }
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
5963 return isAllowed;
5964 }
5965
5966 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08005967 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
5968 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
5969 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5970 throw new SecurityException("Caller does not have carrier privileges on any UICC.");
5971 }
Jordan Liu5aa07002018-12-18 15:44:48 -08005972
5973 final long identity = Binder.clearCallingIdentity();
5974 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08005975 UiccController uiccController = UiccController.getInstance();
5976 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
5977
5978 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
5979 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
5980 // Remove private info if the caller doesn't have access
5981 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
5982 for (UiccCardInfo cardInfo : cardInfos) {
5983 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
5984 UiccProfile profile = card.getUiccProfile();
5985 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
5986 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5987 filteredInfos.add(cardInfo.getUnprivileged());
5988 } else {
5989 filteredInfos.add(cardInfo);
5990 }
5991 }
5992 return filteredInfos;
5993 }
5994 return cardInfos;
5995 } catch (PackageManager.NameNotFoundException e) {
5996 // This should not happen since we pass the package info in from TelephonyManager
5997 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
6001 }
6002
6003 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006004 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006005 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006006
Malcolm Chend965c8b2018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
6009 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6010 if (slots == null) {
6011 Rlog.i(LOG_TAG, "slots is null.");
6012 return null;
6013 }
6014
6015 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6016 for (int i = 0; i < slots.length; i++) {
6017 UiccSlot slot = slots[i];
6018 if (slot == null) {
6019 continue;
6020 }
6021
6022 String cardId;
6023 UiccCard card = slot.getUiccCard();
6024 if (card != null) {
6025 cardId = card.getCardId();
6026 } else {
6027 cardId = slot.getIccId();
6028 }
6029
6030 int cardState = 0;
6031 switch (slot.getCardState()) {
6032 case CARDSTATE_ABSENT:
6033 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6034 break;
6035 case CARDSTATE_PRESENT:
6036 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6037 break;
6038 case CARDSTATE_ERROR:
6039 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6040 break;
6041 case CARDSTATE_RESTRICTED:
6042 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6043 break;
6044 default:
6045 break;
6046
6047 }
6048
6049 infos[i] = new UiccSlotInfo(
6050 slot.isActive(),
6051 slot.isEuicc(),
6052 cardId,
6053 cardState,
6054 slot.getPhoneId(),
6055 slot.isExtendedApduSupported());
6056 }
6057 return infos;
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006060 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006061 }
6062
6063 @Override
6064 public boolean switchSlots(int[] physicalSlots) {
6065 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006073 }
Jack Yu4c988042018-02-27 15:30:01 -08006074
6075 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006076 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 return UiccController.getInstance().getCardIdForDefaultEuicc();
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
6083 }
6084
6085 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006086 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6087 enforceModifyPermission();
6088 final Phone phone = getPhone(subId);
6089 if (phone == null) {
6090 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6091 return;
6092 }
6093
Malcolm Chend965c8b2018-02-28 15:00:40 -08006094 final long identity = Binder.clearCallingIdentity();
6095 try {
6096 phone.setRadioIndicationUpdateMode(filters, mode);
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
Jack Yu4c988042018-02-27 15:30:01 -08006100 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006101
6102 /**
goneil47ffb6e2018-04-06 15:40:58 -07006103 * A test API to reload the UICC profile.
6104 *
6105 * <p>Requires that the calling app has permission
6106 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6107 * @hide
6108 */
6109 @Override
6110 public void refreshUiccProfile(int subId) {
6111 enforceModifyPermission();
6112
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 Phone phone = getPhone(subId);
6116 if (phone == null) {
6117 return;
6118 }
6119 UiccCard uiccCard = phone.getUiccCard();
6120 if (uiccCard == null) {
6121 return;
6122 }
6123 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6124 if (uiccProfile == null) {
6125 return;
6126 }
6127 uiccProfile.refresh();
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
6131 }
6132
6133 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006134 * Returns false if the mobile data is disabled by default, otherwise return true.
6135 */
6136 private boolean getDefaultDataEnabled() {
6137 return "true".equalsIgnoreCase(
6138 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6139 }
6140
6141 /**
6142 * Returns true if the data roaming is enabled by default, i.e the system property
6143 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6144 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6145 */
6146 private boolean getDefaultDataRoamingEnabled(int subId) {
6147 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006148 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006149 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6150 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6151 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6152 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6153 return isDataRoamingEnabled;
6154 }
6155
6156 /**
6157 * Returns the default network type for the given {@code subId}, if the default network type is
6158 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6159 */
6160 private int getDefaultNetworkType(int subId) {
6161 return Integer.parseInt(
6162 TelephonyManager.getTelephonyProperty(
6163 mSubscriptionController.getPhoneId(subId),
6164 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6165 String.valueOf(Phone.PREFERRED_NT_MODE)));
6166 }
fionaxua13278b2018-03-21 00:08:13 -07006167
6168 @Override
6169 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6170 gid1, String gid2, String plmn, String spn) {
6171 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006172
6173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 final Phone phone = getPhone(subId);
6176 if (phone == null) {
6177 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6178 return;
6179 }
6180 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006183 }
fionaxua13278b2018-03-21 00:08:13 -07006184 }
6185
6186 @Override
6187 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006188 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006189
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 final Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6195 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6196 }
6197 return phone.getCarrierIdListVersion();
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006200 }
fionaxua13278b2018-03-21 00:08:13 -07006201 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006202
6203 @Override
6204 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6205 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6206 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6207 return -1;
6208 }
6209
6210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
6216 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006217
6218 @Override
6219 public int getCdmaRoamingMode(int subId) {
6220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6221 mApp, subId, "getCdmaRoamingMode");
6222
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6226 } finally {
6227 Binder.restoreCallingIdentity(identity);
6228 }
6229 }
6230
6231 @Override
6232 public boolean setCdmaRoamingMode(int subId, int mode) {
6233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6234 mApp, subId, "setCdmaRoamingMode");
6235
6236 final long identity = Binder.clearCallingIdentity();
6237 try {
6238 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
6242 }
6243
6244 @Override
6245 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6247 mApp, subId, "setCdmaSubscriptionMode");
6248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
6255 }
chen xu7ee67862018-10-30 22:27:10 -07006256
sqian2fff4a32018-11-05 14:18:37 -08006257 private void ensureUserRunning(int userId) {
6258 if (!mUserManager.isUserRunning(userId)) {
6259 throw new IllegalStateException("User " + userId + " does not exist or not running");
6260 }
6261 }
6262
6263 /**
6264 * Returns a list of SMS apps on a given user.
6265 *
6266 * Only the shell user (UID 2000 or 0) can call it.
6267 * Target user must be running.
6268 */
6269 @Override
6270 public String[] getSmsApps(int userId) {
6271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6272 ensureUserRunning(userId);
6273
6274 final Collection<SmsApplicationData> apps =
6275 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6276
6277 String[] ret = new String[apps.size()];
6278 int i = 0;
6279 for (SmsApplicationData app : apps) {
6280 ret[i++] = app.mPackageName;
6281 }
6282 return ret;
6283 }
6284
6285 /**
6286 * Returns the default SMS app package name on a given user.
6287 *
6288 * Only the shell user (UID 2000 or 0) can call it.
6289 * Target user must be running.
6290 */
6291 @Override
6292 public String getDefaultSmsApp(int userId) {
6293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6294 ensureUserRunning(userId);
6295
6296 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6297 /* updateIfNeeded= */ true, userId);
6298 return cn == null ? null : cn.getPackageName();
6299 }
6300
6301 /**
6302 * Set a package as the default SMS app on a given user.
6303 *
6304 * Only the shell user (UID 2000 or 0) can call it.
6305 * Target user must be running.
6306 */
6307 @Override
6308 public void setDefaultSmsApp(int userId, String packageName) {
6309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6310 ensureUserRunning(userId);
6311
6312 boolean found = false;
6313 for (String pkg : getSmsApps(userId)) {
6314 if (TextUtils.equals(packageName, pkg)) {
6315 found = true;
6316 break;
6317 }
6318 }
6319 if (!found) {
6320 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6321 }
6322
6323 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6324 }
6325
chen xu7ee67862018-10-30 22:27:10 -07006326 @Override
sqian04b86072018-11-07 14:02:21 -08006327 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6328 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6330 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6331 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6332 }
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
sqian991b35e2018-12-12 16:48:18 -08006335 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6336 for (Phone phone: PhoneFactory.getPhones()) {
6337 if (phone.getEmergencyNumberTracker() != null
6338 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6339 emergencyNumberListInternal.put(
6340 phone.getSubId(),
6341 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6342 }
sqian03bca152018-12-05 18:48:28 -08006343 }
sqian991b35e2018-12-12 16:48:18 -08006344 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
sqian04b86072018-11-07 14:02:21 -08006348 }
6349
6350 @Override
sqian03bca152018-12-05 18:48:28 -08006351 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6352 final Phone defaultPhone = getDefaultPhone();
6353 if (!exactMatch) {
6354 TelephonyPermissions
6355 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6356 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6357 }
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
sqian991b35e2018-12-12 16:48:18 -08006360 for (Phone phone: PhoneFactory.getPhones()) {
6361 if (phone.getEmergencyNumberTracker() != null
6362 && phone.getEmergencyNumberTracker() != null) {
6363 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6364 number, exactMatch)) {
6365 return true;
sqian03bca152018-12-05 18:48:28 -08006366 }
6367 }
sqian03bca152018-12-05 18:48:28 -08006368 }
6369 return false;
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
6374
sqian9d4df8b2019-01-15 18:32:07 -08006375 /**
6376 * Update emergency number list for test mode.
6377 */
6378 @Override
6379 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6381 "updateEmergencyNumberListTestMode");
6382
6383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 for (Phone phone: PhoneFactory.getPhones()) {
6386 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6387 if (tracker != null) {
6388 tracker.executeEmergencyNumberTestModeCommand(action, num);
6389 }
6390 }
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
6394 }
6395
6396 /**
6397 * Get the full emergency number list for test mode.
6398 */
6399 @Override
6400 public List<String> getEmergencyNumberListTestMode() {
6401 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6402 "getEmergencyNumberListTestMode");
6403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 Set<String> emergencyNumbers = new HashSet<>();
6407 for (Phone phone: PhoneFactory.getPhones()) {
6408 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6409 if (tracker != null) {
6410 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6411 emergencyNumbers.add(num.getNumber());
6412 }
6413 }
6414 }
6415 return new ArrayList<>(emergencyNumbers);
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
6419 }
6420
sqian04b86072018-11-07 14:02:21 -08006421 @Override
chen xu7ee67862018-10-30 22:27:10 -07006422 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6423 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6424 Phone phone = getPhone(subId);
6425 if (phone == null) {
6426 return null;
6427 }
6428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 UiccProfile profile = UiccController.getInstance()
6431 .getUiccProfileForPhone(phone.getPhoneId());
6432 if (profile != null) {
6433 return profile.getCertsFromCarrierPrivilegeAccessRules();
6434 }
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
6438 return null;
6439 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006440
6441 /**
6442 * Enable or disable a modem stack.
6443 */
6444 @Override
6445 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6446 enforceModifyPermission();
6447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 Phone phone = PhoneFactory.getPhone(slotIndex);
6451 if (phone == null) {
6452 return false;
6453 } else {
6454 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6455 }
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
6459 }
Micheled3107c52018-12-21 15:00:11 -08006460
6461 @Override
6462 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6463 enforceModifyPermission();
6464
6465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 mTelephonySharedPreferences.edit()
6468 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6469 .commit();
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
6475 @Override
6476 public boolean isMultisimCarrierRestricted() {
6477 enforceReadPrivilegedPermission("isMultisimCarrierRestricted");
6478
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6482 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6483 if (numPhysicalSlots < 2) {
6484 loge("isMultisimCarrierRestricted: requires at least 2 cards");
6485 return true;
6486 }
6487
6488 // Default value is false. Multi SIM is allowed unless explicitly restricted.
6489 return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false);
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
6493 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006494
6495 /**
6496 * Switch configs to enable multi-sim or switch back to single-sim
6497 * @param numOfSims number of active sims we want to switch to
6498 */
6499 @Override
6500 public void switchMultiSimConfig(int numOfSims) {
6501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6502 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6503 final long identity = Binder.clearCallingIdentity();
6504 try {
6505 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
6511 /**
6512 * Get how many sims have been activated on the phone
6513 */
6514 @Override
6515 public int getNumOfActiveSims() {
6516 final long identity = Binder.clearCallingIdentity();
6517 try {
6518 return mPhoneConfigurationManager.getNumOfActiveSims();
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006523
6524 /**
6525 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006526 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006527 */
6528 @Override
6529 public boolean isRebootRequiredForModemConfigChange() {
6530 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
6537 }
6538
Pengquan Meng92d253b2019-02-06 11:12:53 -08006539 private void updateModemStateMetrics() {
6540 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6541 // TODO: check the state for each modem if the api is ready.
6542 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6543 }
6544
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006545 @Override
6546 public int[] getSlotsMapping() {
6547 enforceReadPrivilegedPermission("getSlotsMapping");
6548
6549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6552 // All logical slots should have a mapping to a physical slot.
6553 int[] logicalSlotsMapping = new int[phoneCount];
6554 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6555 for (int i = 0; i < slotInfos.length; i++) {
6556 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6557 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6558 }
6559 }
6560 return logicalSlotsMapping;
6561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
6564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006565}