blob: ad17964f59418f501ede1de0705ee0c21663a035 [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;
Derek Tan740e1672017-06-27 14:56:27 -0700136import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137import com.android.internal.telephony.uicc.IccIoResult;
138import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800139import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700140import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800141import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000144import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700145import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800146import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700147import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800148import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700149import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700150import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700152import java.io.FileDescriptor;
153import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800154import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800157import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800158import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800159import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100160import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
163/**
164 * Implementation of the ITelephony interface.
165 */
Santos Cordon117fee72014-05-16 17:56:12 -0700166public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 private static final String LOG_TAG = "PhoneInterfaceManager";
168 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
169 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171
172 // Message codes used with mMainThreadHandler
173 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700174 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
175 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176 private static final int CMD_OPEN_CHANNEL = 9;
177 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
178 private static final int CMD_CLOSE_CHANNEL = 11;
179 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800180 private static final int CMD_NV_READ_ITEM = 13;
181 private static final int EVENT_NV_READ_ITEM_DONE = 14;
182 private static final int CMD_NV_WRITE_ITEM = 15;
183 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
184 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
185 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700186 private static final int CMD_RESET_MODEM_CONFIG = 19;
187 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800188 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
189 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
190 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
191 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800192 private static final int CMD_SEND_ENVELOPE = 25;
193 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000194 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
195 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700196 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
197 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
198 private static final int CMD_EXCHANGE_SIM_IO = 31;
199 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800200 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
201 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700202 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
203 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700204 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
205 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
207 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
208 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
209 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700210 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
211 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
212 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
213 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700214 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800215 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
216 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000217 private static final int CMD_SWITCH_SLOTS = 50;
218 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700219 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
220 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
221 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
222 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
223 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
224 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
225 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
226 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700227 private static final int CMD_GET_ALL_CELL_INFO = 60;
228 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
229 private static final int CMD_GET_CELL_LOCATION = 62;
230 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700231 private static final int CMD_MODEM_REBOOT = 64;
232 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700233 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
234 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800236 // Parameters of select command.
237 private static final int SELECT_COMMAND = 0xA4;
238 private static final int SELECT_P1 = 0x04;
239 private static final int SELECT_P2 = 0;
240 private static final int SELECT_P3 = 0x10;
241
Pengquan Meng85728fb2018-03-12 16:31:21 -0700242 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
243 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
244 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
245
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 /** The singleton instance. */
247 private static PhoneInterfaceManager sInstance;
248
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800250 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700251 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private AppOpsManager mAppOps;
253 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800254 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700256 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Derek Tan97ebb422014-09-05 16:55:38 -0700258 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
259 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800261 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700262
Derek Tan740e1672017-06-27 14:56:27 -0700263 // The AID of ISD-R.
264 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
265
yinxub1bed742017-04-17 11:45:04 -0700266 private NetworkScanRequestTracker mNetworkScanRequestTracker;
267
David Kelly5e06a7f2018-03-12 14:10:59 +0000268 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
269 private static final int MANUFACTURER_CODE_LENGTH = 8;
270
Derek Tan89e89d42014-07-08 17:00:10 -0700271 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700272 * A request object to use for transmitting data to an ICC.
273 */
274 private static final class IccAPDUArgument {
275 public int channel, cla, command, p1, p2, p3;
276 public String data;
277
278 public IccAPDUArgument(int channel, int cla, int command,
279 int p1, int p2, int p3, String data) {
280 this.channel = channel;
281 this.cla = cla;
282 this.command = command;
283 this.p1 = p1;
284 this.p2 = p2;
285 this.p3 = p3;
286 this.data = data;
287 }
288 }
289
290 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700291 * A request object to use for transmitting data to an ICC.
292 */
293 private static final class ManualNetworkSelectionArgument {
294 public OperatorInfo operatorInfo;
295 public boolean persistSelection;
296
297 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
298 this.operatorInfo = operatorInfo;
299 this.persistSelection = persistSelection;
300 }
301 }
302
303 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
305 * request after sending. The main thread will notify the request when it is complete.
306 */
307 private static final class MainThreadRequest {
308 /** The argument to use for the request */
309 public Object argument;
310 /** The result of the request that is run on the main thread */
311 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800312 // The subscriber id that this request applies to. Defaults to
313 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
314 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
Nathan Harold92bed182018-10-12 18:16:49 -0700316 // In cases where subId is unavailable, the caller needs to specify the phone.
317 public Phone phone;
318
vagdevie435a3e2018-08-15 16:01:53 -0700319 public WorkSource workSource;
320
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 public MainThreadRequest(Object argument) {
322 this.argument = argument;
323 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800324
Nathan Harold92bed182018-10-12 18:16:49 -0700325 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
326 this.argument = argument;
327 if (phone != null) {
328 this.phone = phone;
329 }
330 this.workSource = workSource;
331 }
332
vagdevie435a3e2018-08-15 16:01:53 -0700333 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800334 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800335 if (subId != null) {
336 this.subId = subId;
337 }
vagdevie435a3e2018-08-15 16:01:53 -0700338 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 }
341
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800342 private static final class IncomingThirdPartyCallArgs {
343 public final ComponentName component;
344 public final String callId;
345 public final String callerDisplayName;
346
347 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
348 String callerDisplayName) {
349 this.component = component;
350 this.callId = callId;
351 this.callerDisplayName = callerDisplayName;
352 }
353 }
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /**
356 * A handler that processes messages on the main thread in the phone process. Since many
357 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
358 * inbound binder threads to the main thread in the phone process. The Binder thread
359 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
360 * on, which will be notified when the operation completes and will contain the result of the
361 * request.
362 *
363 * <p>If a MainThreadRequest object is provided in the msg.obj field,
364 * note that request.result must be set to something non-null for the calling thread to
365 * unblock.
366 */
367 private final class MainThreadHandler extends Handler {
368 @Override
369 public void handleMessage(Message msg) {
370 MainThreadRequest request;
371 Message onCompleted;
372 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800373 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700374 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800375 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
377 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700378 case CMD_HANDLE_USSD_REQUEST: {
379 request = (MainThreadRequest) msg.obj;
380 final Phone phone = getPhoneFromRequest(request);
381 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
382 String ussdRequest = ussdObject.first;
383 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700384
Pengquan Meng0c05b502018-09-06 09:59:22 -0700385 if (!isUssdApiAllowed(request.subId)) {
386 // Carrier does not support use of this API, return failure.
387 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
388 UssdResponse response = new UssdResponse(ussdRequest, null);
389 Bundle returnData = new Bundle();
390 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
391 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700392
Pengquan Meng0c05b502018-09-06 09:59:22 -0700393 request.result = true;
394 notifyRequester(request);
395 return;
396 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700397
Pengquan Meng0c05b502018-09-06 09:59:22 -0700398 try {
399 request.result = phone != null
400 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
401 } catch (CallStateException cse) {
402 request.result = false;
403 }
404 // Wake up the requesting thread
405 notifyRequester(request);
406 break;
pkanwar32d516d2016-10-14 19:37:38 -0700407 }
408
Yorke Lee716f67e2015-06-17 15:39:16 -0700409 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700411 final Phone phone = getPhoneFromRequest(request);
412 request.result = phone != null ?
413 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
414 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700416 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800423 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 if (uiccCard == null) {
425 loge("iccTransmitApduLogicalChannel: No UICC");
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700427 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
430 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 iccArgument.channel, iccArgument.cla, iccArgument.command,
433 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 break;
437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 ar = (AsyncResult) msg.obj;
440 request = (MainThreadRequest) ar.userObj;
441 if (ar.exception == null && ar.result != null) {
442 request.result = ar.result;
443 } else {
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
445 if (ar.result == null) {
446 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800447 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800449 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 } else {
451 loge("iccTransmitApduLogicalChannel: Unknown exception");
452 }
453 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700454 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 break;
456
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
458 request = (MainThreadRequest) msg.obj;
459 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800460 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 if (uiccCard == null) {
462 loge("iccTransmitApduBasicChannel: No UICC");
463 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700464 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 } else {
466 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
467 request);
468 uiccCard.iccTransmitApduBasicChannel(
469 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
470 iccArgument.p3, iccArgument.data, onCompleted);
471 }
472 break;
473
474 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
475 ar = (AsyncResult) msg.obj;
476 request = (MainThreadRequest) ar.userObj;
477 if (ar.exception == null && ar.result != null) {
478 request.result = ar.result;
479 } else {
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
481 if (ar.result == null) {
482 loge("iccTransmitApduBasicChannel: Empty response");
483 } else if (ar.exception instanceof CommandException) {
484 loge("iccTransmitApduBasicChannel: CommandException: " +
485 ar.exception);
486 } else {
487 loge("iccTransmitApduBasicChannel: Unknown exception");
488 }
489 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 break;
492
493 case CMD_EXCHANGE_SIM_IO:
494 request = (MainThreadRequest) msg.obj;
495 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 if (uiccCard == null) {
498 loge("iccExchangeSimIO: No UICC");
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700500 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 } else {
502 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
503 request);
504 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
505 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
506 iccArgument.data, onCompleted);
507 }
508 break;
509
510 case EVENT_EXCHANGE_SIM_IO_DONE:
511 ar = (AsyncResult) msg.obj;
512 request = (MainThreadRequest) ar.userObj;
513 if (ar.exception == null && ar.result != null) {
514 request.result = ar.result;
515 } else {
516 request.result = new IccIoResult(0x6f, 0, (byte[])null);
517 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 break;
520
Derek Tan4d5e5c12014-02-04 11:54:58 -0800521 case CMD_SEND_ENVELOPE:
522 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800523 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 if (uiccCard == null) {
525 loge("sendEnvelopeWithStatus: No UICC");
526 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 } else {
529 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
530 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
531 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 break;
533
534 case EVENT_SEND_ENVELOPE_DONE:
535 ar = (AsyncResult) msg.obj;
536 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700537 if (ar.exception == null && ar.result != null) {
538 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 if (ar.result == null) {
542 loge("sendEnvelopeWithStatus: Empty response");
543 } else if (ar.exception instanceof CommandException) {
544 loge("sendEnvelopeWithStatus: CommandException: " +
545 ar.exception);
546 } else {
547 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
548 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700550 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 break;
552
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 case CMD_OPEN_CHANNEL:
554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800556 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800559 request.result = new IccOpenLogicalChannelResponse(-1,
560 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 } else {
563 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
565 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 break;
568
569 case EVENT_OPEN_CHANNEL_DONE:
570 ar = (AsyncResult) msg.obj;
571 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 int[] result = (int[]) ar.result;
575 int channelId = result[0];
576 byte[] selectResponse = null;
577 if (result.length > 1) {
578 selectResponse = new byte[result.length - 1];
579 for (int i = 1; i < result.length; ++i) {
580 selectResponse[i - 1] = (byte) result[i];
581 }
582 }
583 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700584 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 if (ar.result == null) {
587 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 if (ar.exception != null) {
590 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
591 }
592
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700594 if (ar.exception instanceof CommandException) {
595 CommandException.Error error =
596 ((CommandException) (ar.exception)).getCommandError();
597 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700599 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700600 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 }
602 }
603 openChannelResp = new IccOpenLogicalChannelResponse(
604 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700606 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case CMD_CLOSE_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 if (uiccCard == null) {
614 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900615 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
619 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
620 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
623 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800624 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
625 break;
626
627 case CMD_NV_READ_ITEM:
628 request = (MainThreadRequest) msg.obj;
629 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800630 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
631 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800632 break;
633
634 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 ar = (AsyncResult) msg.obj;
636 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800637 if (ar.exception == null && ar.result != null) {
638 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800640 request.result = "";
641 if (ar.result == null) {
642 loge("nvReadItem: Empty response");
643 } else if (ar.exception instanceof CommandException) {
644 loge("nvReadItem: CommandException: " +
645 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800647 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 }
649 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
Jake Hambye994d462014-02-03 13:10:13 -0800653 case CMD_NV_WRITE_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
656 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800657 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700658 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800659 break;
660
661 case EVENT_NV_WRITE_ITEM_DONE:
662 handleNullReturnEvent(msg, "nvWriteItem");
663 break;
664
665 case CMD_NV_WRITE_CDMA_PRL:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800668 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800669 break;
670
671 case EVENT_NV_WRITE_CDMA_PRL_DONE:
672 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
673 break;
674
chen xu1cc0abe2018-10-26 17:39:23 -0700675 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800676 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700677 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800678 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800679 break;
680
chen xu1cc0abe2018-10-26 17:39:23 -0700681 case EVENT_RESET_MODEM_CONFIG_DONE:
682 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800683 break;
684
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 case CMD_GET_PREFERRED_NETWORK_TYPE:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700688 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800689 break;
690
691 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
692 ar = (AsyncResult) msg.obj;
693 request = (MainThreadRequest) ar.userObj;
694 if (ar.exception == null && ar.result != null) {
695 request.result = ar.result; // Integer
696 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800697 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 if (ar.result == null) {
699 loge("getPreferredNetworkType: Empty response");
700 } else if (ar.exception instanceof CommandException) {
701 loge("getPreferredNetworkType: CommandException: " +
702 ar.exception);
703 } else {
704 loge("getPreferredNetworkType: Unknown exception");
705 }
706 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700707 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 break;
709
710 case CMD_SET_PREFERRED_NETWORK_TYPE:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
713 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
718 handleNullReturnEvent(msg, "setPreferredNetworkType");
719 break;
720
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
722 request = (MainThreadRequest)msg.obj;
723 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800724 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000725 break;
726
727 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
728 ar = (AsyncResult)msg.obj;
729 request = (MainThreadRequest)ar.userObj;
730 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700731 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000732 break;
733
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800734 case CMD_SET_VOICEMAIL_NUMBER:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
737 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800738 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
739 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800740 break;
741
742 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
743 handleNullReturnEvent(msg, "setVoicemailNumber");
744 break;
745
Stuart Scott54788802015-03-30 13:18:01 -0700746 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
749 request);
750 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
751 break;
752
753 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
754 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
755 break;
756
Shishir Agrawal302c8692015-06-19 13:49:39 -0700757 case CMD_PERFORM_NETWORK_SCAN:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
760 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
761 break;
762
763 case EVENT_PERFORM_NETWORK_SCAN_DONE:
764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
766 CellNetworkScanResult cellScanResult;
767 if (ar.exception == null && ar.result != null) {
768 cellScanResult = new CellNetworkScanResult(
769 CellNetworkScanResult.STATUS_SUCCESS,
770 (List<OperatorInfo>) ar.result);
771 } else {
772 if (ar.result == null) {
773 loge("getCellNetworkScanResults: Empty response");
774 }
775 if (ar.exception != null) {
776 loge("getCellNetworkScanResults: Exception: " + ar.exception);
777 }
778 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
779 if (ar.exception instanceof CommandException) {
780 CommandException.Error error =
781 ((CommandException) (ar.exception)).getCommandError();
782 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
783 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
784 } else if (error == CommandException.Error.GENERIC_FAILURE) {
785 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
786 }
787 }
788 cellScanResult = new CellNetworkScanResult(errorCode, null);
789 }
790 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700791 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700792 break;
793
794 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
795 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 ManualNetworkSelectionArgument selArg =
797 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
799 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700800 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
801 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 break;
803
804 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 if (ar.exception == null) {
808 request.result = true;
809 } else {
810 request.result = false;
811 loge("setNetworkSelectionModeManual " + ar.exception);
812 }
813 notifyRequester(request);
814 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 break;
816
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 case CMD_GET_MODEM_ACTIVITY_INFO:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800820 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700821 break;
822
823 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
826 if (ar.exception == null && ar.result != null) {
827 request.result = ar.result;
828 } else {
829 if (ar.result == null) {
830 loge("queryModemActivityInfo: Empty response");
831 } else if (ar.exception instanceof CommandException) {
832 loge("queryModemActivityInfo: CommandException: " +
833 ar.exception);
834 } else {
835 loge("queryModemActivityInfo: Unknown exception");
836 }
837 }
Amit Mahajand4766222016-01-28 15:28:28 -0800838 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
839 if (request.result == null) {
840 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
841 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700842 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 break;
844
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 case CMD_SET_ALLOWED_CARRIERS:
846 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800847 CarrierRestrictionRules argument =
848 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700849 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800850 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700851 break;
852
853 case EVENT_SET_ALLOWED_CARRIERS_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800859 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
860 if (ar.exception instanceof CommandException) {
861 loge("setAllowedCarriers: CommandException: " + ar.exception);
862 CommandException.Error error =
863 ((CommandException) (ar.exception)).getCommandError();
864 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
865 request.result =
866 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
867 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 } else {
869 loge("setAllowedCarriers: Unknown exception");
870 }
871 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700872 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 break;
874
875 case CMD_GET_ALLOWED_CARRIERS:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800878 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_GET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800887 request.result = new IllegalStateException(
888 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 if (ar.result == null) {
890 loge("getAllowedCarriers: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("getAllowedCarriers: CommandException: " +
893 ar.exception);
894 } else {
895 loge("getAllowedCarriers: Unknown exception");
896 }
897 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700898 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 break;
900
Nathan Haroldb3014052017-01-25 15:57:32 -0800901 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result;
906 } else {
907 request.result = new IllegalArgumentException(
908 "Failed to retrieve Forbidden Plmns");
909 if (ar.result == null) {
910 loge("getForbiddenPlmns: Empty response");
911 } else {
912 loge("getForbiddenPlmns: Unknown exception");
913 }
914 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700915 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 break;
917
918 case CMD_GET_FORBIDDEN_PLMNS:
919 request = (MainThreadRequest) msg.obj;
920 uiccCard = getUiccCardFromRequest(request);
921 if (uiccCard == null) {
922 loge("getForbiddenPlmns() UiccCard is null");
923 request.result = new IllegalArgumentException(
924 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700925 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 break;
927 }
928 Integer appType = (Integer) request.argument;
929 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
930 if (uiccApp == null) {
931 loge("getForbiddenPlmns() no app with specified type -- "
932 + appType);
933 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700934 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 break;
936 } else {
937 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
938 + " specified type -- " + appType);
939 }
940 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
941 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
942 onCompleted);
943 break;
944
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000945 case CMD_SWITCH_SLOTS:
946 request = (MainThreadRequest) msg.obj;
947 int[] physicalSlots = (int[]) request.argument;
948 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
949 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
950 break;
951
952 case EVENT_SWITCH_SLOTS_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700956 notifyRequester(request);
957 break;
958 case CMD_GET_NETWORK_SELECTION_MODE:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
961 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
962 break;
963
964 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception != null) {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
969 } else {
970 int mode = ((int[]) ar.result)[0];
971 if (mode == 0) {
972 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
973 } else {
974 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
975 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700977 notifyRequester(request);
978 break;
979 case CMD_GET_CDMA_ROAMING_MODE:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
982 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
983 break;
984 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception != null) {
988 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
989 } else {
990 request.result = ((int[]) ar.result)[0];
991 }
992 notifyRequester(request);
993 break;
994 case CMD_SET_CDMA_ROAMING_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
997 int mode = (int) request.argument;
998 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
999 break;
1000 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 request.result = ar.exception == null;
1004 notifyRequester(request);
1005 break;
1006 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1009 int subscriptionMode = (int) request.argument;
1010 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1011 break;
1012 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = ar.exception == null;
1016 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 case CMD_GET_ALL_CELL_INFO:
1019 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001021 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001022 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 case EVENT_GET_ALL_CELL_INFO_DONE:
1024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001026 // If a timeout occurs, the response will be null
1027 request.result = (ar.exception == null && ar.result != null)
1028 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001029 synchronized (request) {
1030 request.notifyAll();
1031 }
1032 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001033 case CMD_REQUEST_CELL_INFO_UPDATE:
1034 request = (MainThreadRequest) msg.obj;
1035 request.phone.requestCellInfoUpdate(request.workSource,
1036 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1037 break;
1038 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1042 try {
1043 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001044 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001045 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1046 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001047 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001048 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001049 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001050 } else {
1051 // use the result as returned
1052 cb.onCellInfo((List<CellInfo>) ar.result);
1053 }
1054 } catch (RemoteException re) {
1055 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1056 }
1057 break;
1058 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 request = (MainThreadRequest) msg.obj;
1060 WorkSource ws = (WorkSource) request.argument;
1061 Phone phone = getPhoneFromRequest(request);
1062 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1063 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
1067 if (ar.exception == null) {
1068 request.result = ar.result;
1069 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001070 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1072 ? new CdmaCellLocation() : new GsmCellLocation();
1073 }
1074
1075 synchronized (request) {
1076 request.notifyAll();
1077 }
1078 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001079 case CMD_MODEM_REBOOT:
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001082 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001083 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001084 case EVENT_CMD_MODEM_REBOOT_DONE:
1085 handleNullReturnEvent(msg, "rebootModem");
1086 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 default:
1088 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1089 break;
1090 }
1091 }
Jake Hambye994d462014-02-03 13:10:13 -08001092
Pengquan Meng0c05b502018-09-06 09:59:22 -07001093 private void notifyRequester(MainThreadRequest request) {
1094 synchronized (request) {
1095 request.notifyAll();
1096 }
1097 }
1098
Jake Hambye994d462014-02-03 13:10:13 -08001099 private void handleNullReturnEvent(Message msg, String command) {
1100 AsyncResult ar = (AsyncResult) msg.obj;
1101 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1102 if (ar.exception == null) {
1103 request.result = true;
1104 } else {
1105 request.result = false;
1106 if (ar.exception instanceof CommandException) {
1107 loge(command + ": CommandException: " + ar.exception);
1108 } else {
1109 loge(command + ": Unknown exception");
1110 }
1111 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001112 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 }
1115
1116 /**
1117 * Posts the specified command to be executed on the main thread,
1118 * waits for the request to complete, and returns the result.
1119 * @see #sendRequestAsync
1120 */
1121 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001122 return sendRequest(
1123 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001124 }
1125
1126 /**
1127 * Posts the specified command to be executed on the main thread,
1128 * waits for the request to complete, and returns the result.
1129 * @see #sendRequestAsync
1130 */
1131 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1132 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001133 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001134 }
1135
1136 /**
1137 * Posts the specified command to be executed on the main thread,
1138 * waits for the request to complete, and returns the result.
1139 * @see #sendRequestAsync
1140 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001141 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001142 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001143 }
1144
1145 /**
1146 * Posts the specified command to be executed on the main thread,
1147 * waits for the request to complete, and returns the result.
1148 * @see #sendRequestAsync
1149 */
Nathan Harold92bed182018-10-12 18:16:49 -07001150 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1151 return sendRequest(command, argument, subId, null, workSource);
1152 }
1153
1154 /**
1155 * Posts the specified command to be executed on the main thread,
1156 * waits for the request to complete, and returns the result.
1157 * @see #sendRequestAsync
1158 */
1159 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1160 return sendRequest(
1161 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1162 }
1163
1164 /**
1165 * Posts the specified command to be executed on the main thread,
1166 * waits for the request to complete, and returns the result.
1167 * @see #sendRequestAsync
1168 */
1169 private Object sendRequest(
1170 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1172 throw new RuntimeException("This method will deadlock if called from the main thread.");
1173 }
1174
Nathan Harold92bed182018-10-12 18:16:49 -07001175 MainThreadRequest request = null;
1176 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1177 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1178 } else if (phone != null) {
1179 request = new MainThreadRequest(argument, phone, workSource);
1180 } else {
1181 request = new MainThreadRequest(argument, subId, workSource);
1182 }
1183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 Message msg = mMainThreadHandler.obtainMessage(command, request);
1185 msg.sendToTarget();
1186
1187 // Wait for the request to complete
1188 synchronized (request) {
1189 while (request.result == null) {
1190 try {
1191 request.wait();
1192 } catch (InterruptedException e) {
1193 // Do nothing, go back and wait until the request is complete
1194 }
1195 }
1196 }
1197 return request.result;
1198 }
1199
1200 /**
1201 * Asynchronous ("fire and forget") version of sendRequest():
1202 * Posts the specified command to be executed on the main thread, and
1203 * returns immediately.
1204 * @see #sendRequest
1205 */
1206 private void sendRequestAsync(int command) {
1207 mMainThreadHandler.sendEmptyMessage(command);
1208 }
1209
1210 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001211 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001212 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001213 */
1214 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001215 sendRequestAsync(command, argument, null, null);
1216 }
1217
1218 /**
1219 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1220 * @see {@link #sendRequest(int,Object)}
1221 */
1222 private void sendRequestAsync(
1223 int command, Object argument, Phone phone, WorkSource workSource) {
1224 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001225 Message msg = mMainThreadHandler.obtainMessage(command, request);
1226 msg.sendToTarget();
1227 }
1228
1229 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 * Initialize the singleton PhoneInterfaceManager instance.
1231 * This is only done once, at startup, from PhoneApp.onCreate().
1232 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001233 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 synchronized (PhoneInterfaceManager.class) {
1235 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001236 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 } else {
1238 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1239 }
1240 return sInstance;
1241 }
1242 }
1243
1244 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001245 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001248 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1250 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001251 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001252 mTelephonySharedPreferences =
1253 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001254 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001255 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 publish();
1258 }
1259
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001260 private Phone getDefaultPhone() {
1261 Phone thePhone = getPhone(getDefaultSubscription());
1262 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1263 }
1264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 private void publish() {
1266 if (DBG) log("publish: " + this);
1267
1268 ServiceManager.addService("phone", this);
1269 }
1270
Stuart Scott584921c2015-01-15 17:10:34 -08001271 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001272 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001273 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001274 }
1275
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001276 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1277 Phone phone = getPhoneFromRequest(request);
1278 return phone == null ? null :
1279 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1280 }
1281
Wink Saville36469e72014-06-11 15:17:00 -07001282 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001283 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001284 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286
1287 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001288 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001289 }
1290
Wink Savilleb564aae2014-10-23 10:18:09 -07001291 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 if (DBG) log("dial: " + number);
1293 // No permission check needed here: This is just a wrapper around the
1294 // ACTION_DIAL intent, which is available to any app since it puts up
1295 // the UI before it does anything.
1296
Malcolm Chend965c8b2018-02-28 15:00:40 -08001297 final long identity = Binder.clearCallingIdentity();
1298 try {
1299 String url = createTelUrl(number);
1300 if (url == null) {
1301 return;
1302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303
Malcolm Chend965c8b2018-02-28 15:00:40 -08001304 // PENDING: should we just silently fail if phone is offhook or ringing?
1305 PhoneConstants.State state = mCM.getState(subId);
1306 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1307 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1308 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1309 mApp.startActivity(intent);
1310 }
1311 } finally {
1312 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 }
1314 }
1315
1316 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Wink Savilleb564aae2014-10-23 10:18:09 -07001320 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 if (DBG) log("call: " + number);
1322
1323 // This is just a wrapper around the ACTION_CALL intent, but we still
1324 // need to do a permission check since we're calling startActivity()
1325 // from the context of the phone app.
1326 enforceCallPermission();
1327
1328 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1329 != AppOpsManager.MODE_ALLOWED) {
1330 return;
1331 }
1332
Malcolm Chend965c8b2018-02-28 15:00:40 -08001333 final long identity = Binder.clearCallingIdentity();
1334 try {
1335 String url = createTelUrl(number);
1336 if (url == null) {
1337 return;
1338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339
Malcolm Chend965c8b2018-02-28 15:00:40 -08001340 boolean isValid = false;
1341 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1342 if (slist != null) {
1343 for (SubscriptionInfo subInfoRecord : slist) {
1344 if (subInfoRecord.getSubscriptionId() == subId) {
1345 isValid = true;
1346 break;
1347 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001348 }
Wink Saville08874612014-08-31 19:19:58 -07001349 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001350 if (!isValid) {
1351 return;
1352 }
Wink Saville08874612014-08-31 19:19:58 -07001353
Malcolm Chend965c8b2018-02-28 15:00:40 -08001354 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1355 intent.putExtra(SUBSCRIPTION_KEY, subId);
1356 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1357 mApp.startActivity(intent);
1358 } finally {
1359 Binder.restoreCallingIdentity(identity);
1360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 }
1362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001365 }
1366
Wink Savilleb564aae2014-10-23 10:18:09 -07001367 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001369 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1370 }
1371
1372 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001374 }
1375
Wink Savilleb564aae2014-10-23 10:18:09 -07001376 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001377 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001378 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1379 }
1380
1381 /** {@hide} */
1382 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001383 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001384 }
1385
Wink Savilleb564aae2014-10-23 10:18:09 -07001386 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001388
1389 final long identity = Binder.clearCallingIdentity();
1390 try {
1391 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1392 checkSimPin.start();
1393 return checkSimPin.unlockSim(null, pin);
1394 } finally {
1395 Binder.restoreCallingIdentity(identity);
1396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 }
1398
Wink Saville9de0f752013-10-22 19:04:03 -07001399 /** {@hide} */
1400 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001401 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001402 }
1403
Wink Savilleb564aae2014-10-23 10:18:09 -07001404 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001406
1407 final long identity = Binder.clearCallingIdentity();
1408 try {
1409 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1410 checkSimPuk.start();
1411 return checkSimPuk.unlockSim(puk, pin);
1412 } finally {
1413 Binder.restoreCallingIdentity(identity);
1414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 }
1416
1417 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001418 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 * a synchronous one.
1420 */
1421 private static class UnlockSim extends Thread {
1422
1423 private final IccCard mSimCard;
1424
1425 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001426 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1427 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428
1429 // For replies from SimCard interface
1430 private Handler mHandler;
1431
1432 // For async handler to identify request type
1433 private static final int SUPPLY_PIN_COMPLETE = 100;
1434
1435 public UnlockSim(IccCard simCard) {
1436 mSimCard = simCard;
1437 }
1438
1439 @Override
1440 public void run() {
1441 Looper.prepare();
1442 synchronized (UnlockSim.this) {
1443 mHandler = new Handler() {
1444 @Override
1445 public void handleMessage(Message msg) {
1446 AsyncResult ar = (AsyncResult) msg.obj;
1447 switch (msg.what) {
1448 case SUPPLY_PIN_COMPLETE:
1449 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1450 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001451 mRetryCount = msg.arg1;
1452 if (ar.exception != null) {
1453 if (ar.exception instanceof CommandException &&
1454 ((CommandException)(ar.exception)).getCommandError()
1455 == CommandException.Error.PASSWORD_INCORRECT) {
1456 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1457 } else {
1458 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1459 }
1460 } else {
1461 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 mDone = true;
1464 UnlockSim.this.notifyAll();
1465 }
1466 break;
1467 }
1468 }
1469 };
1470 UnlockSim.this.notifyAll();
1471 }
1472 Looper.loop();
1473 }
1474
1475 /*
1476 * Use PIN or PUK to unlock SIM card
1477 *
1478 * If PUK is null, unlock SIM card with PIN
1479 *
1480 * If PUK is not null, unlock SIM card with PUK and set PIN code
1481 */
Wink Saville9de0f752013-10-22 19:04:03 -07001482 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483
1484 while (mHandler == null) {
1485 try {
1486 wait();
1487 } catch (InterruptedException e) {
1488 Thread.currentThread().interrupt();
1489 }
1490 }
1491 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1492
1493 if (puk == null) {
1494 mSimCard.supplyPin(pin, callback);
1495 } else {
1496 mSimCard.supplyPuk(puk, pin, callback);
1497 }
1498
1499 while (!mDone) {
1500 try {
1501 Log.d(LOG_TAG, "wait for done");
1502 wait();
1503 } catch (InterruptedException e) {
1504 // Restore the interrupted status
1505 Thread.currentThread().interrupt();
1506 }
1507 }
1508 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001509 int[] resultArray = new int[2];
1510 resultArray[0] = mResult;
1511 resultArray[1] = mRetryCount;
1512 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 }
1514 }
1515
1516 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001517 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001518
1519 }
1520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 // No permission check needed here: this call is harmless, and it's
1523 // needed for the ServiceState.requestStateUpdate() call (which is
1524 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001525 final long identity = Binder.clearCallingIdentity();
1526 try {
1527 final Phone phone = getPhone(subId);
1528 if (phone != null) {
1529 phone.updateServiceLocation();
1530 }
1531 } finally {
1532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001536 @Override
1537 public boolean isRadioOn(String callingPackage) {
1538 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001541 @Override
1542 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001544 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001545 return false;
1546 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001547
1548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 return isRadioOnForSubscriber(subId);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001554 }
1555
1556 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 final Phone phone = getPhone(subId);
1560 if (phone != null) {
1561 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1562 } else {
1563 return false;
1564 }
1565 } finally {
1566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 }
1569
1570 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001571 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 }
Wink Saville36469e72014-06-11 15:17:00 -07001573
Wink Savilleb564aae2014-10-23 10:18:09 -07001574 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001576
1577 final long identity = Binder.clearCallingIdentity();
1578 try {
1579 final Phone phone = getPhone(subId);
1580 if (phone != null) {
1581 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1582 }
1583 } finally {
1584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 }
Wink Saville36469e72014-06-11 15:17:00 -07001586 }
1587
1588 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001589 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001590 }
1591
Wink Savilleb564aae2014-10-23 10:18:09 -07001592 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001593 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001594
1595 final long identity = Binder.clearCallingIdentity();
1596 try {
1597 final Phone phone = getPhone(subId);
1598 if (phone == null) {
1599 return false;
1600 }
1601 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1602 toggleRadioOnOffForSubscriber(subId);
1603 }
1604 return true;
1605 } finally {
1606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
Wink Saville36469e72014-06-11 15:17:00 -07001609
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001610 public boolean needMobileRadioShutdown() {
1611 /*
1612 * If any of the Radios are available, it will need to be
1613 * shutdown. So return true if any Radio is available.
1614 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001615 final long identity = Binder.clearCallingIdentity();
1616 try {
1617 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1618 Phone phone = PhoneFactory.getPhone(i);
1619 if (phone != null && phone.isRadioAvailable()) return true;
1620 }
1621 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1622 return false;
1623 } finally {
1624 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001625 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001626 }
1627
Malcolm Chend965c8b2018-02-28 15:00:40 -08001628 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001629 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001630 enforceModifyPermission();
1631
1632 final long identity = Binder.clearCallingIdentity();
1633 try {
1634 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1635 logv("Shutting down Phone " + i);
1636 shutdownRadioUsingPhoneId(i);
1637 }
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 }
1641 }
1642
1643 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001644 Phone phone = PhoneFactory.getPhone(phoneId);
1645 if (phone != null && phone.isRadioAvailable()) {
1646 phone.shutdownRadio();
1647 }
1648 }
1649
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001651 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001652
1653 final long identity = Binder.clearCallingIdentity();
1654 try {
1655 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1656 if (defaultPhone != null) {
1657 defaultPhone.setRadioPower(turnOn);
1658 return true;
1659 } else {
1660 loge("There's no default phone.");
1661 return false;
1662 }
1663 } finally {
1664 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001665 }
Wink Saville36469e72014-06-11 15:17:00 -07001666 }
1667
Wink Savilleb564aae2014-10-23 10:18:09 -07001668 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001670
1671 final long identity = Binder.clearCallingIdentity();
1672 try {
1673 final Phone phone = getPhone(subId);
1674 if (phone != null) {
1675 phone.setRadioPower(turnOn);
1676 return true;
1677 } else {
1678 return false;
1679 }
1680 } finally {
1681 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
Wink Saville36469e72014-06-11 15:17:00 -07001685 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001686 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 public boolean enableDataConnectivity() {
1688 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001689
1690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 int subId = mSubscriptionController.getDefaultDataSubId();
1693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001695 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001696 return true;
1697 } else {
1698 return false;
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
Wink Saville36469e72014-06-11 15:17:00 -07001705 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 public boolean disableDataConnectivity() {
1708 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001709
1710 final long identity = Binder.clearCallingIdentity();
1711 try {
1712 int subId = mSubscriptionController.getDefaultDataSubId();
1713 final Phone phone = getPhone(subId);
1714 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001715 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001716 return true;
1717 } else {
1718 return false;
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001726 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 final Phone phone = getPhone(subId);
1730 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001731 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001732 } else {
1733 return false;
1734 }
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
1740 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001741 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001742 }
1743
pkanwarae03a6b2016-11-06 20:37:09 -08001744 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001745 enforceCallPermission();
1746
1747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1750 return;
1751 }
1752 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1753 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1754 } finally {
1755 Binder.restoreCallingIdentity(identity);
1756 }
pkanwar32d516d2016-10-14 19:37:38 -07001757 };
1758
Wink Savilleb564aae2014-10-23 10:18:09 -07001759 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001761
1762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1765 return false;
1766 }
1767 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001774 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001775 }
1776
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001777 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 Phone phone = PhoneFactory.getPhone(slotIndex);
1781 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1782 PhoneConstantConversions.convertCallState(phone.getState());
1783 } finally {
1784 Binder.restoreCallingIdentity(identity);
1785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 }
1787
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1793 if (phone != null) {
1794 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1795 } else {
1796 return PhoneConstantConversions.convertDataState(
1797 PhoneConstants.DataState.DISCONNECTED);
1798 }
1799 } finally {
1800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1809 if (phone != null) {
1810 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1811 } else {
1812 return TelephonyManager.DATA_ACTIVITY_NONE;
1813 }
1814 } finally {
1815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
1819 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001820 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001821 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001822 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001823 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1824 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001825 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001828 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 if (DBG_LOC) log("getCellLocation: is active user");
1832 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001833 int subId = mSubscriptionController.getDefaultDataSubId();
1834 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1835 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001836 return data;
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
1839 }
Svetoslav64fad262015-04-14 14:35:21 -07001840 }
1841
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001843 public String getNetworkCountryIsoForPhone(int phoneId) {
1844 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1845 // registered cell info, so return a NULL country instead.
1846 final long identity = Binder.clearCallingIdentity();
1847 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001848 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1849 // Get default phone in this case.
1850 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1851 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001852 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001853 // Todo: fix this when we can get the actual cellular network info when the device
1854 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001855 if (TelephonyManager.NETWORK_TYPE_IWLAN
1856 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1857 return "";
1858 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001859 Phone phone = PhoneFactory.getPhone(phoneId);
1860 if (phone != null) {
1861 ServiceStateTracker sst = phone.getServiceStateTracker();
1862 if (sst != null) {
1863 LocaleTracker lt = sst.getLocaleTracker();
1864 if (lt != null) {
1865 return lt.getCurrentCountry();
1866 }
1867 }
1868 }
1869 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001870 } finally {
1871 Binder.restoreCallingIdentity(identity);
1872 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001873 }
1874
1875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001877 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001878 }
1879
Sanket Padawe356d7632015-06-22 14:03:32 -07001880 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001881 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 mApp.enforceCallingOrSelfPermission(
1883 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001884
1885 final long identity = Binder.clearCallingIdentity();
1886 try {
1887 final Phone phone = getPhone(subId);
1888 if (phone != null) {
1889 phone.enableLocationUpdates();
1890 }
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
1896 @Override
1897 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.disableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
Nathan Harold31d7ff32018-10-15 20:20:30 -07001917 /**
1918 * Returns the target SDK version number for a given package name.
1919 *
1920 * @return target SDK if the package is found or INT_MAX.
1921 */
1922 private int getTargetSdk(String packageName) {
1923 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001924 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1925 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001926 if (ai != null) return ai.targetSdkVersion;
1927 } catch (PackageManager.NameNotFoundException unexpected) {
1928 }
1929 return Integer.MAX_VALUE;
1930 }
1931
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 @Override
1933 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001934 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1935 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001936 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1937 throw new SecurityException(
1938 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1939 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001940
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1942 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1943 return null;
1944 }
Svetoslav64fad262015-04-14 14:35:21 -07001945
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001946 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947
Nathan Haroldf180aac2018-06-01 18:43:55 -07001948 List<CellInfo> info = getAllCellInfo(callingPackage);
1949 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950
Nathan Haroldf180aac2018-06-01 18:43:55 -07001951 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1952 for (CellInfo ci : info) {
1953 if (ci instanceof CellInfoGsm) {
1954 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1955 } else if (ci instanceof CellInfoWcdma) {
1956 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001959 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001962 private List<CellInfo> getCachedCellInfo() {
1963 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1964 for (Phone phone : PhoneFactory.getPhones()) {
1965 List<CellInfo> info = phone.getAllCellInfo();
1966 if (info != null) cellInfos.addAll(info);
1967 }
1968 return cellInfos;
1969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970
1971 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001972 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001973 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001974 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001975 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001976 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001977 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001980 final int targetSdk = getTargetSdk(callingPackage);
1981 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1982 return getCachedCellInfo();
1983 }
1984
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001985 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1990 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001991 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001992 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001993 if (info != null) cellInfos.addAll(info);
1994 }
1995 return cellInfos;
1996 } finally {
1997 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999 }
2000
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002001 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002002 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2003 requestCellInfoUpdateInternal(
2004 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2005 }
2006
2007 @Override
2008 public void requestCellInfoUpdateWithWorkSource(
2009 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2010 enforceModifyPermission();
2011 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2012 }
2013
2014 private void requestCellInfoUpdateInternal(
2015 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002016 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002018 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2019 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002020 return;
2021 }
2022
2023 final Phone phone = getPhone(subId);
2024 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2025
2026 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2027 }
2028
2029 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002031 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002033
2034 final long identity = Binder.clearCallingIdentity();
2035 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002036 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002037 } finally {
2038 Binder.restoreCallingIdentity(identity);
2039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 }
2041
Shishir Agrawala9f32182016-04-12 12:00:16 -07002042 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002043 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002044 Phone phone = PhoneFactory.getPhone(slotIndex);
2045 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002046 return null;
2047 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002048 int subId = phone.getSubId();
2049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2050 mApp, subId, callingPackage, "getImeiForSlot")) {
2051 return null;
2052 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002053
2054 final long identity = Binder.clearCallingIdentity();
2055 try {
2056 return phone.getImei();
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
2059 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002060 }
2061
2062 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002063 public String getTypeAllocationCodeForSlot(int slotIndex) {
2064 Phone phone = PhoneFactory.getPhone(slotIndex);
2065 String tac = null;
2066 if (phone != null) {
2067 String imei = phone.getImei();
2068 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2069 }
2070 return tac;
2071 }
2072
2073 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002074 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002075 Phone phone = PhoneFactory.getPhone(slotIndex);
2076 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002077 return null;
2078 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002079
Jeff Davidson913390f2018-02-23 17:11:49 -08002080 int subId = phone.getSubId();
2081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2082 mApp, subId, callingPackage, "getMeidForSlot")) {
2083 return null;
2084 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002085
2086 final long identity = Binder.clearCallingIdentity();
2087 try {
2088 return phone.getMeid();
2089 } finally {
2090 Binder.restoreCallingIdentity(identity);
2091 }
Jack Yu2af8d712017-03-15 17:14:14 -07002092 }
2093
2094 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002095 public String getManufacturerCodeForSlot(int slotIndex) {
2096 Phone phone = PhoneFactory.getPhone(slotIndex);
2097 String manufacturerCode = null;
2098 if (phone != null) {
2099 String meid = phone.getMeid();
2100 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2101 }
2102 return manufacturerCode;
2103 }
2104
2105 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002106 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002107 Phone phone = PhoneFactory.getPhone(slotIndex);
2108 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002109 return null;
2110 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002111 int subId = phone.getSubId();
2112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2113 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2114 return null;
2115 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 return phone.getDeviceSvn();
2120 } finally {
2121 Binder.restoreCallingIdentity(identity);
2122 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002123 }
2124
fionaxu43304da2017-11-27 22:51:16 -08002125 @Override
2126 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002127 final long identity = Binder.clearCallingIdentity();
2128 try {
2129 final Phone phone = getPhone(subId);
2130 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
2133 }
fionaxu43304da2017-11-27 22:51:16 -08002134 }
2135
2136 @Override
2137 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 final Phone phone = getPhone(subId);
2141 return phone == null ? null : phone.getCarrierName();
2142 } finally {
2143 Binder.restoreCallingIdentity(identity);
2144 }
fionaxu43304da2017-11-27 22:51:16 -08002145 }
2146
calvinpaneed9ae82018-11-01 19:43:06 +08002147 @Override
chen xuc93cc282018-11-04 17:17:00 -08002148 public int getSubscriptionPreciseCarrierId(int subId) {
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 final Phone phone = getPhone(subId);
2152 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2153 : phone.getPreciseCarrierId();
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
2156 }
2157 }
2158
2159 @Override
2160 public String getSubscriptionPreciseCarrierName(int subId) {
2161 final long identity = Binder.clearCallingIdentity();
2162 try {
2163 final Phone phone = getPhone(subId);
2164 return phone == null ? null : phone.getPreciseCarrierName();
2165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
2168 }
2169
chen xu02581692018-11-11 19:03:44 -08002170 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002171 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2172 if (!isSubscriptionMccMnc) {
2173 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2174 }
chen xu02581692018-11-11 19:03:44 -08002175 final Phone phone = PhoneFactory.getPhone(slotIndex);
2176 if (phone == null) {
2177 return TelephonyManager.UNKNOWN_CARRIER_ID;
2178 }
2179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
2184 }
2185 }
2186
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 //
2188 // Internal helper methods.
2189 //
2190
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002191 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2193 *
2194 * @throws SecurityException if the caller does not have the required permission
2195 */
2196 private void enforceModifyPermission() {
2197 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2198 }
2199
2200 /**
2201 * Make sure the caller has the CALL_PHONE permission.
2202 *
2203 * @throws SecurityException if the caller does not have the required permission
2204 */
2205 private void enforceCallPermission() {
2206 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2207 }
2208
Stuart Scott8eef64f2015-04-08 15:13:54 -07002209 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002210 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002211 "ConnectivityService");
2212 }
2213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 private String createTelUrl(String number) {
2215 if (TextUtils.isEmpty(number)) {
2216 return null;
2217 }
2218
Jake Hambye994d462014-02-03 13:10:13 -08002219 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
Ihab Awadf9e92732013-12-05 18:02:52 -08002222 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2224 }
2225
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002226 private static void logv(String msg) {
2227 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2228 }
2229
Ihab Awadf9e92732013-12-05 18:02:52 -08002230 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2232 }
2233
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002236 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002237 }
2238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002240 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = PhoneFactory.getPhone(slotIndex);
2244 if (phone == null) {
2245 return PhoneConstants.PHONE_TYPE_NONE;
2246 } else {
2247 return phone.getPhoneType();
2248 }
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
2254 /**
2255 * Returns the CDMA ERI icon index to display
2256 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 @Override
2258 public int getCdmaEriIconIndex(String callingPackage) {
2259 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002260 }
2261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002265 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002266 return -1;
2267 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 if (phone != null) {
2273 return phone.getCdmaEriIconIndex();
2274 } else {
2275 return -1;
2276 }
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
2282 /**
2283 * Returns the CDMA ERI icon mode,
2284 * 0 - ON
2285 * 1 - FLASHING
2286 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 @Override
2288 public int getCdmaEriIconMode(String callingPackage) {
2289 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002290 }
2291
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002295 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002296 return -1;
2297 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002298
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 final Phone phone = getPhone(subId);
2302 if (phone != null) {
2303 return phone.getCdmaEriIconMode();
2304 } else {
2305 return -1;
2306 }
2307 } finally {
2308 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
2311
2312 /**
2313 * Returns the CDMA ERI text,
2314 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 @Override
2316 public String getCdmaEriText(String callingPackage) {
2317 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002321 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002323 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 return null;
2325 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 final Phone phone = getPhone(subId);
2330 if (phone != null) {
2331 return phone.getCdmaEriText();
2332 } else {
2333 return null;
2334 }
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 }
2339
2340 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002341 * Returns the CDMA MDN.
2342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2346 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002351 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002352 return phone.getLine1Number();
2353 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002354 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002355 return null;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002359 }
2360 }
2361
2362 /**
2363 * Returns the CDMA MIN.
2364 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2368 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002369
2370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = getPhone(subId);
2373 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2374 return phone.getCdmaMin();
2375 } else {
2376 return null;
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002380 }
2381 }
2382
Hall Liud892bec2018-11-30 14:51:45 -08002383 @Override
2384 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2385 INumberVerificationCallback callback, String callingPackage) {
2386 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2387 != PERMISSION_GRANTED) {
2388 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2389 }
2390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2391
2392 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2393 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2394 throw new SecurityException("Calling package must be configured in the device config");
2395 }
2396
2397 if (range == null) {
2398 throw new NullPointerException("Range must be non-null");
2399 }
2400
2401 timeoutMillis = Math.min(timeoutMillis,
2402 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2403
2404 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2405 }
2406
Junda Liuca05d5d2014-08-14 22:36:34 -07002407 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 * Returns true if CDMA provisioning needs to run.
2409 */
2410 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002411 final long identity = Binder.clearCallingIdentity();
2412 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002413 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002414 } finally {
2415 Binder.restoreCallingIdentity(identity);
2416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418
2419 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002420 * Sets the voice mail number of a given subId.
2421 */
2422 @Override
2423 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002424 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2429 new Pair<String, String>(alphaTag, number), new Integer(subId));
2430 return success;
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
2433 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002434 }
2435
Ta-wei Yen87c49842016-05-13 21:19:52 -07002436 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002437 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002439 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002440 if (!TextUtils.equals(callingPackage, systemDialer)) {
2441 throw new SecurityException("caller must be system dialer");
2442 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2447 if (phoneAccountHandle == null) {
2448 return null;
2449 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002450 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002451 } finally {
2452 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002453 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002454 }
2455
2456 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002457 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002460 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002461 return null;
2462 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002463
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002464 final long identity = Binder.clearCallingIdentity();
2465 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002466 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002470 }
2471
2472 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002473 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2474 VisualVoicemailSmsFilterSettings settings) {
2475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002480 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002484 }
2485
2486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002487 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002493 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002497 }
2498
2499 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002500 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2501 String callingPackage, int subId) {
2502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002507 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002511 }
2512
2513 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002514 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002515 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002516
2517 final long identity = Binder.clearCallingIdentity();
2518 try {
2519 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002520 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002524 }
2525
2526 @Override
2527 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2528 String number, int port, String text, PendingIntent sentIntent) {
2529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002530 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002531 enforceSendSmsPermission();
2532 // Make the calls as the phone process.
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2536 if (port == 0) {
2537 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2538 sentIntent, null, false);
2539 } else {
2540 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2541 smsManager.sendDataMessageWithSelfPermissions(number, null,
2542 (short) port, data, sentIntent, null);
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002547 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002548 /**
fionaxu0152e512016-11-14 13:36:14 -08002549 * Sets the voice activation state of a given subId.
2550 */
2551 @Override
2552 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2554 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 final Phone phone = getPhone(subId);
2559 if (phone != null) {
2560 phone.setVoiceActivationState(activationState);
2561 } else {
2562 loge("setVoiceActivationState fails with invalid subId: " + subId);
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002566 }
2567 }
2568
2569 /**
2570 * Sets the data activation state of a given subId.
2571 */
2572 @Override
2573 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2575 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setDataActivationState(activationState);
2582 } else {
2583 loge("setVoiceActivationState fails with invalid subId: " + subId);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002587 }
2588 }
2589
2590 /**
2591 * Returns the voice activation state of a given subId.
2592 */
2593 @Override
2594 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002595 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596
fionaxu0152e512016-11-14 13:36:14 -08002597 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 if (phone != null) {
2601 return phone.getVoiceActivationState();
2602 } else {
2603 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002607 }
2608 }
2609
2610 /**
2611 * Returns the data activation state of a given subId.
2612 */
2613 @Override
2614 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002615 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002616
fionaxu0152e512016-11-14 13:36:14 -08002617 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 if (phone != null) {
2621 return phone.getDataActivationState();
2622 } else {
2623 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002627 }
2628 }
2629
2630 /**
Wink Saville36469e72014-06-11 15:17:00 -07002631 * Returns the unread count of voicemails for a subId
2632 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002634 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2636 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2637 return 0;
2638 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 return phone.getVoiceMessageCount();
2644 } else {
2645 return 0;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
2652 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002653 * returns true, if the device is in a state where both voice and data
2654 * are supported simultaneously. This can change based on location or network condition.
2655 */
2656 @Override
2657 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 final Phone phone = getPhone(subId);
2661 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002665 }
2666
2667 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002668 * Send the dialer code if called from the current default dialer or the caller has
2669 * carrier privilege.
2670 * @param inputCode The dialer code to send
2671 */
2672 @Override
2673 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002674 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002676 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2677 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002678 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002679 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2680 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002681 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002685 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
fionaxu235cc5e2017-03-06 22:25:57 -08002689 }
2690
2691 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002692 * Returns the data network type.
2693 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 *
2695 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2696 */
2697 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002698 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 final Phone phone = getPhone(getDefaultSubscription());
2702 if (phone != null) {
2703 return phone.getServiceState().getDataNetworkType();
2704 } else {
2705 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2706 }
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002709 }
Wink Saville36469e72014-06-11 15:17:00 -07002710 }
2711
Pengquan Meng0c05b502018-09-06 09:59:22 -07002712 @Override
2713 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002714 if (!isActiveSubscription(subId)) {
2715 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2716 }
2717
Pengquan Meng0c05b502018-09-06 09:59:22 -07002718 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2719 }
2720
Brad Ebinger4c460712018-10-01 10:40:55 -07002721 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002722 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2723 throws RemoteException {
2724 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002725 final long token = Binder.clearCallingIdentity();
2726 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002728 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002729 .addRegistrationCallbackForSubscription(c, subId);
2730 } finally {
2731 Binder.restoreCallingIdentity(token);
2732 }
2733 }
2734
2735 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002736 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2737 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002738 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2739 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2740 }
2741 Binder.withCleanCallingIdentity(() -> {
2742 try {
2743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002744 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002745 .removeRegistrationCallbackForSubscription(c, subId);
2746 } catch (IllegalArgumentException e) {
2747 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2748 + "is inactive, ignoring unregister.");
2749 // If the subscription is no longer active, just return, since the callback
2750 // will already have been removed internally.
2751 }
2752 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002753 }
2754
2755 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002756 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2757 throws RemoteException {
2758 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2760 final long token = Binder.clearCallingIdentity();
2761 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002763 .addCapabilitiesCallbackForSubscription(c, subId);
2764 } finally {
2765 Binder.restoreCallingIdentity(token);
2766 }
2767 }
2768
2769 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002770 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2771 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002772
2773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2775 }
2776 Binder.withCleanCallingIdentity(() -> {
2777 try {
2778 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002780 .removeCapabilitiesCallbackForSubscription(c, subId);
2781 } catch (IllegalArgumentException e) {
2782 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2783 + "is inactive, ignoring unregister.");
2784 // If the subscription is no longer active, just return, since the callback
2785 // will already have been removed internally.
2786 }
2787 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002788 }
2789
2790 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002791 public boolean isCapable(int subId, int capability, int regTech) {
2792 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2794 final long token = Binder.clearCallingIdentity();
2795 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002796 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002797 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2798 } catch (ImsException e) {
2799 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2800 return false;
2801 } finally {
2802 Binder.restoreCallingIdentity(token);
2803 }
2804 }
2805
2806 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002807 public boolean isAvailable(int subId, int capability, int regTech) {
2808 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002809 final long token = Binder.clearCallingIdentity();
2810 try {
2811 Phone phone = getPhone(subId);
2812 if (phone == null) return false;
2813 return phone.isImsCapabilityAvailable(capability, regTech);
2814 } finally {
2815 Binder.restoreCallingIdentity(token);
2816 }
2817 }
2818
2819 @Override
2820 public boolean isAdvancedCallingSettingEnabled(int subId) {
2821 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2823 final long token = Binder.clearCallingIdentity();
2824 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002825 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002826 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2827 } finally {
2828 Binder.restoreCallingIdentity(token);
2829 }
2830 }
2831
2832 @Override
2833 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2835 "setAdvancedCallingSetting");
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002839 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002840 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
2843 }
2844 }
2845
2846 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002847 public boolean isVtSettingEnabled(int subId) {
2848 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002852 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002853 getSlotIndexOrException(subId)).isVtEnabledByUser();
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
2856 }
2857 }
2858
2859 @Override
2860 public void setVtSetting(int subId, boolean isEnabled) {
2861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2862 "setVtSetting");
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002866 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 @Override
2873 public boolean isVoWiFiSettingEnabled(int subId) {
2874 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2875 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)).isWfcEnabledByUser();
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
2885 @Override
2886 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2888 "setVoWiFiSetting");
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)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002893 } finally {
2894 Binder.restoreCallingIdentity(identity);
2895 }
2896 }
2897
2898 @Override
2899 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2900 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
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)).isWfcRoamingEnabledByUser();
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 }
2910
2911 @Override
2912 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2914 "setVoWiFiRoamingSetting");
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,
Brad Ebinger4c460712018-10-01 10:40:55 -07002919 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
2922 }
2923 }
2924
2925 @Override
2926 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2928 "setVoWiFiNonPersistent");
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002932 boolean isRoaming = TelephonyManager.from(
2933 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002934 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002935 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07002936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
2939 }
2940
2941 @Override
2942 public int getVoWiFiModeSetting(int subId) {
2943 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002947 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
2951 }
2952 }
2953
2954 @Override
2955 public void setVoWiFiModeSetting(int subId, int mode) {
2956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2957 "setVoWiFiModeSetting");
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002961 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002962 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 @Override
2969 public int getVoWiFiRoamingModeSetting(int subId) {
2970 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002974 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002975 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
2982 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2984 "setVoWiFiRoamingModeSetting");
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002988 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002989 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
2993 }
2994
2995 @Override
2996 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2998 "setRttCapabilityEnabled");
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003002 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003003 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public boolean isTtyOverVolteEnabled(int subId) {
3011 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003015 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003016 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003022 @Override
3023 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3024 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
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, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003029 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
3033 }
3034
3035 @Override
3036 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3037 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3038 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003039 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3040 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3041 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003044 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003045 .removeProvisioningCallbackForSubscription(callback, subId);
3046 } catch (IllegalArgumentException e) {
3047 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3048 + "is inactive, ignoring unregister.");
3049 // If the subscription is no longer active, just return, since the callback will already
3050 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003057 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3058 boolean isProvisioned) {
3059 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3060 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3061 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3062 }
3063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3064 "setProvisioningStatusForCapability");
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3068 Phone phone = getPhone(subId);
3069 if (phone == null) {
3070 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3071 + subId);
3072 return;
3073 }
3074 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3075 return;
3076 }
3077
3078 // this capability requires provisioning, route to the correct API.
3079 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3080 switch (capability) {
3081 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3082 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3083 ims.setVolteProvisioned(isProvisioned);
3084 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3085 ims.setWfcProvisioned(isProvisioned);
3086 }
3087 break;
3088 }
3089 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3090 // There is currently no difference in VT provisioning type.
3091 ims.setVtProvisioned(isProvisioned);
3092 break;
3093 }
3094 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3095 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3096 // change the capability of the feature instead if needed.
3097 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3098 == isProvisioned) {
3099 // No change in provisioning.
3100 return;
3101 }
3102 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3103 try {
3104 ims.changeMmTelCapability(capability, tech, isProvisioned);
3105 } catch (ImsException e) {
3106 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3107 + ", Exception" + e.getMessage());
3108 }
3109 break;
3110 }
3111 default: {
3112 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3113 + capability + "', which does not require provisioning.");
3114 }
3115 }
3116
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
3123 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3124 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3125 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3126 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3127 }
3128 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3132 Phone phone = getPhone(subId);
3133 if (phone == null) {
3134 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3135 + subId);
3136 // We will fail with "true" as the provisioning status because this is the default
3137 // if we do not require provisioning.
3138 return true;
3139 }
3140
3141 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3142 return true;
3143 }
3144
3145 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3146 switch (capability) {
3147 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3148 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3149 return ims.isVolteProvisionedOnDevice();
3150 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3151 return ims.isWfcProvisionedOnDevice();
3152 }
3153 // This should never happen, since we are checking tech above to make sure it
3154 // is either LTE or IWLAN.
3155 throw new IllegalArgumentException("Invalid radio technology for voice "
3156 + "capability.");
3157 }
3158 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3159 // There is currently no difference in VT provisioning type.
3160 return ims.isVtProvisionedOnDevice();
3161 }
3162 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3163 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3164 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3165 }
3166 default: {
3167 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3168 + capability + "', which does not require provisioning.");
3169 }
3170 }
3171
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
3174 }
3175 }
3176
3177 @Override
3178 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3179 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3180 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3181 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3182 }
3183 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3184 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3185 return (provisionedBits & capability) > 0;
3186 }
3187
3188 @Override
3189 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3190 boolean isProvisioned) {
3191 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3192 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3193 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3194 }
3195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3196 "setProvisioningStatusForCapability");
3197 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3198 // If the current provisioning status for capability already matches isProvisioned,
3199 // do nothing.
3200 if (((provisionedBits & capability) > 0) == isProvisioned) {
3201 return;
3202 }
3203 if (isProvisioned) {
3204 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3205 } else {
3206 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3207 }
3208 }
3209
3210 /**
3211 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3212 * technology. The bitfield should mirror the bitfield defined by
3213 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3214 */
3215 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3216 String key = getMmTelProvisioningKey(subId, tech);
3217 // Default is no capabilities are provisioned.
3218 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3219 }
3220
3221 /**
3222 * Sets the MmTel capability provisioning bitfield (defined by
3223 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3224 * technology specified.
3225 *
3226 * Note: This is a synchronous command and should not be called on UI thread.
3227 */
3228 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3229 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3230 String key = getMmTelProvisioningKey(subId, tech);
3231 editor.putInt(key, newField);
3232 editor.commit();
3233 }
3234
3235 private static String getMmTelProvisioningKey(int subId, int tech) {
3236 // resulting key is provision_ims_mmtel_{subId}_{tech}
3237 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3238 }
3239
3240 /**
3241 * Query CarrierConfig to see if the specified capability requires provisioning for the
3242 * carrier associated with the subscription id.
3243 */
3244 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3245 int capability) {
3246 CarrierConfigManager configManager = new CarrierConfigManager(context);
3247 PersistableBundle c = configManager.getConfigForSubId(subId);
3248 boolean requireUtProvisioning = c.getBoolean(
3249 // By default, this config is true (even if there is no SIM). We also check to make
3250 // sure the subscription needs provisioning here, so we do not need to check for
3251 // the no-SIM case, where we would normally shortcut this to false.
3252 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3253 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3254 false);
3255 boolean requireVoiceVtProvisioning = c.getBoolean(
3256 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3257
3258 // First check to make sure that the capability requires provisioning.
3259 switch (capability) {
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3261 // intentional fallthrough
3262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3263 if (requireVoiceVtProvisioning) {
3264 // Voice and Video requires provisioning
3265 return true;
3266 }
3267 break;
3268 }
3269 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3270 if (requireUtProvisioning) {
3271 // UT requires provisioning
3272 return true;
3273 }
3274 break;
3275 }
3276 }
3277 return false;
3278 }
3279
3280 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003281 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003282 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3283 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3284 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003285 enforceReadPrivilegedPermission("getImsProvisioningInt");
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003289 int slotId = getSlotIndex(subId);
3290 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3291 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3292 + subId + "' for key:" + key);
3293 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3294 }
3295 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003296 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003297 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3298 + subId + "' for key:" + key);
3299 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
3303 }
3304
3305 @Override
3306 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003307 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3308 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3309 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003310 enforceReadPrivilegedPermission("getImsProvisioningString");
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003314 int slotId = getSlotIndex(subId);
3315 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3316 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3317 + subId + "' for key:" + key);
3318 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3319 }
3320 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003321 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003322 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3323 + subId + "' for key:" + key);
3324 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
3328 }
3329
3330 @Override
3331 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003332 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3333 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3334 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3336 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003337 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, "setImsProvisioningInt: called with an inactive subscription id '"
3343 + subId + "' for key:" + key);
3344 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3345 }
3346 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003347 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003348 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3349 + "' for key:" + key);
3350 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
3357 public int setImsProvisioningString(int subId, int key, String 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 "setImsProvisioningString");
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, "setImsProvisioningString: 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, "setImsProvisioningString: 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
Brad Ebinger4c460712018-10-01 10:40:55 -07003382 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3383 int slotId = SubscriptionManager.getSlotIndex(subId);
3384 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3385 throw new IllegalArgumentException("Invalid Subscription Id.");
3386 }
3387 return slotId;
3388 }
3389
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003390 private int getSlotIndex(int subId) {
3391 int slotId = SubscriptionManager.getSlotIndex(subId);
3392 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3393 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3394 }
3395 return slotId;
3396 }
3397
Wink Saville36469e72014-06-11 15:17:00 -07003398 /**
3399 * Returns the network type for a subId
3400 */
3401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003402 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003404 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003405 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3406 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003407
Malcolm Chend965c8b2018-02-28 15:00:40 -08003408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 if (phone != null) {
3412 return phone.getServiceState().getDataNetworkType();
3413 } else {
3414 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419 }
3420
3421 /**
3422 * Returns the data network type
3423 */
3424 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003425 public int getDataNetworkType(String callingPackage) {
3426 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003427 }
3428
3429 /**
3430 * Returns the data network type for a subId
3431 */
3432 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003433 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003435 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003436 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3437 }
3438
Malcolm Chend965c8b2018-02-28 15:00:40 -08003439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 final Phone phone = getPhone(subId);
3442 if (phone != null) {
3443 return phone.getServiceState().getDataNetworkType();
3444 } else {
3445 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3446 }
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 }
3451
3452 /**
Wink Saville36469e72014-06-11 15:17:00 -07003453 * Returns the Voice network type for a subId
3454 */
3455 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003456 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003458 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003459 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3460 }
3461
Malcolm Chend965c8b2018-02-28 15:00:40 -08003462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 final Phone phone = getPhone(subId);
3465 if (phone != null) {
3466 return phone.getServiceState().getVoiceNetworkType();
3467 } else {
3468 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3469 }
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 }
3474
3475 /**
3476 * @return true if a ICC card is present
3477 */
3478 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003479 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003480 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3481 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003482 }
3483
3484 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003485 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003486 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003487 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003488 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 final Phone phone = PhoneFactory.getPhone(slotIndex);
3492 if (phone != null) {
3493 return phone.getIccCard().hasIccCard();
3494 } else {
3495 return false;
3496 }
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 }
3501
3502 /**
3503 * Return if the current radio is LTE on CDMA. This
3504 * is a tri-state return value as for a period of time
3505 * the mode may be unknown.
3506 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003509 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003511 @Override
3512 public int getLteOnCdmaMode(String callingPackage) {
3513 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003514 }
3515
Sanket Padawe356d7632015-06-22 14:03:32 -07003516 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003517 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003519 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003520 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3521 }
3522
Malcolm Chend965c8b2018-02-28 15:00:40 -08003523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 final Phone phone = getPhone(subId);
3526 if (phone == null) {
3527 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3528 } else {
3529 return phone.getLteOnCdmaMode();
3530 }
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003533 }
Wink Saville36469e72014-06-11 15:17:00 -07003534 }
3535
Wink Saville36469e72014-06-11 15:17:00 -07003536 /**
3537 * {@hide}
3538 * Returns Default subId, 0 in the case of single standby.
3539 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003540 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003541 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003542 }
3543
Shishir Agrawala9f32182016-04-12 12:00:16 -07003544 private int getSlotForDefaultSubscription() {
3545 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3546 }
3547
Wink Savilleb564aae2014-10-23 10:18:09 -07003548 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003549 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003550 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003551
Pengquan Meng466e2482018-09-21 15:54:48 -07003552 private boolean isActiveSubscription(int subId) {
3553 return mSubscriptionController.isActiveSubId(subId);
3554 }
3555
Ihab Awadf2177b72013-11-25 13:33:23 -08003556 /**
3557 * @see android.telephony.TelephonyManager.WifiCallingChoices
3558 */
3559 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003562 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003563 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3564 getWhenToMakeWifiCallsDefaultPreference());
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003568 }
3569
3570 /**
3571 * @see android.telephony.TelephonyManager.WifiCallingChoices
3572 */
3573 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003577 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003578 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003582 }
3583
Sailesh Nepald1e68152013-12-12 19:08:02 -08003584 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003585 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003586 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003587 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003588
Shishir Agrawal566b7612013-10-28 14:41:00 -07003589 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003590 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3591 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3593 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003595
Malcolm Chend965c8b2018-02-28 15:00:40 -08003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 if (TextUtils.equals(ISDR_AID, aid)) {
3599 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003600 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3601 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003602 if (bestComponent == null
3603 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3604 loge("The calling package is not allowed to access ISD-R.");
3605 throw new SecurityException(
3606 "The calling package is not allowed to access ISD-R.");
3607 }
Derek Tan740e1672017-06-27 14:56:27 -07003608 }
Derek Tan740e1672017-06-27 14:56:27 -07003609
Malcolm Chend965c8b2018-02-28 15:00:40 -08003610 if (DBG) {
3611 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3612 }
3613 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3614 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3615 if (DBG) log("iccOpenLogicalChannel: " + response);
3616 return response;
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
3619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003620 }
3621
3622 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003623 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3625 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003626
Malcolm Chend965c8b2018-02-28 15:00:40 -08003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3630 if (channel < 0) {
3631 return false;
3632 }
3633 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3634 if (DBG) log("iccCloseLogicalChannel: " + success);
3635 return success;
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003639 }
3640
3641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003642 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003643 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3645 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003646
Malcolm Chend965c8b2018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 if (DBG) {
3650 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3651 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3652 + p3 + " data=" + data);
3653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003654
Malcolm Chend965c8b2018-02-28 15:00:40 -08003655 if (channel < 0) {
3656 return "";
3657 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003658
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3660 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3661 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003662
Malcolm Chend965c8b2018-02-28 15:00:40 -08003663 // Append the returned status code to the end of the response payload.
3664 String s = Integer.toHexString(
3665 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3666 if (response.payload != null) {
3667 s = IccUtils.bytesToHexString(response.payload) + s;
3668 }
3669 return s;
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003673 }
Jake Hambye994d462014-02-03 13:10:13 -08003674
Evan Charltonc66da362014-05-16 14:06:40 -07003675 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003676 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3677 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3679 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003681
Malcolm Chend965c8b2018-02-28 15:00:40 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3685 && TextUtils.equals(ISDR_AID, data)) {
3686 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003687 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3688 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003689 if (bestComponent == null
3690 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3691 loge("The calling package is not allowed to select ISD-R.");
3692 throw new SecurityException(
3693 "The calling package is not allowed to select ISD-R.");
3694 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003695 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003696
Malcolm Chend965c8b2018-02-28 15:00:40 -08003697 if (DBG) {
3698 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3699 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3700 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003701
Malcolm Chend965c8b2018-02-28 15:00:40 -08003702 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3703 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3704 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003705
Malcolm Chend965c8b2018-02-28 15:00:40 -08003706 // Append the returned status code to the end of the response payload.
3707 String s = Integer.toHexString(
3708 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3709 if (response.payload != null) {
3710 s = IccUtils.bytesToHexString(response.payload) + s;
3711 }
3712 return s;
3713 } finally {
3714 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003715 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003716 }
3717
3718 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003719 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003720 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3722 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003723
Malcolm Chend965c8b2018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 if (DBG) {
3727 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3728 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3729 }
3730
3731 IccIoResult response =
3732 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3733 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3734 subId);
3735
3736 if (DBG) {
3737 log("Exchange SIM_IO [R]" + response);
3738 }
3739
3740 byte[] result = null;
3741 int length = 2;
3742 if (response.payload != null) {
3743 length = 2 + response.payload.length;
3744 result = new byte[length];
3745 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3746 } else {
3747 result = new byte[length];
3748 }
3749
3750 result[length - 1] = (byte) response.sw2;
3751 result[length - 2] = (byte) response.sw1;
3752 return result;
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003755 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003756 }
3757
Nathan Haroldb3014052017-01-25 15:57:32 -08003758 /**
3759 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3760 * on a particular subscription
3761 */
sqianb6e41952018-03-12 14:54:01 -07003762 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3764 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3765 return null;
3766 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003767
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 if (appType != TelephonyManager.APPTYPE_USIM
3771 && appType != TelephonyManager.APPTYPE_SIM) {
3772 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3773 return null;
3774 }
3775 Object response = sendRequest(
3776 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3777 if (response instanceof String[]) {
3778 return (String[]) response;
3779 }
3780 // Response is an Exception of some kind,
3781 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003782 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003785 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003786 }
3787
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003788 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003789 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3791 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003792
Malcolm Chend965c8b2018-02-28 15:00:40 -08003793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3796 if (response.payload == null) {
3797 return "";
3798 }
Evan Charltonc66da362014-05-16 14:06:40 -07003799
Malcolm Chend965c8b2018-02-28 15:00:40 -08003800 // Append the returned status code to the end of the response payload.
3801 String s = Integer.toHexString(
3802 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3803 s = IccUtils.bytesToHexString(response.payload) + s;
3804 return s;
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
3807 }
Evan Charltonc66da362014-05-16 14:06:40 -07003808 }
3809
Jake Hambye994d462014-02-03 13:10:13 -08003810 /**
3811 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3812 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3813 *
3814 * @param itemID the ID of the item to read
3815 * @return the NV item as a String, or null on error.
3816 */
3817 @Override
3818 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3821 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822
3823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003826 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003827 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3828 return value;
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Jake Hambye994d462014-02-03 13:10:13 -08003832 }
3833
3834 /**
3835 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3836 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3837 *
3838 * @param itemID the ID of the item to read
3839 * @param itemValue the value to write, as a String
3840 * @return true on success; false on any failure
3841 */
3842 @Override
3843 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003844 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3851 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003852 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3854 return success;
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
Jake Hambye994d462014-02-03 13:10:13 -08003858 }
3859
3860 /**
3861 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3862 * Used for device configuration by some CDMA operators.
3863 *
3864 * @param preferredRoamingList byte array containing the new PRL
3865 * @return true on success; false on any failure
3866 */
3867 @Override
3868 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3875 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3876 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3877 return success;
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
Jake Hambye994d462014-02-03 13:10:13 -08003881 }
3882
3883 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003884 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003885 * Used for device configuration by some CDMA operators.
3886 *
chen xu1cc0abe2018-10-26 17:39:23 -07003887 * @param slotIndex - device slot.
3888 *
Jake Hambye994d462014-02-03 13:10:13 -08003889 * @return true on success; false on any failure
3890 */
3891 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003892 public boolean resetModemConfig(int slotIndex) {
3893 Phone phone = PhoneFactory.getPhone(slotIndex);
3894 if (phone != null) {
3895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3896 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003897
chen xu1cc0abe2018-10-26 17:39:23 -07003898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3901 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3902 return success;
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003906 }
chen xu1cc0abe2018-10-26 17:39:23 -07003907 return false;
3908 }
3909
3910 /**
3911 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3912 *
3913 * @param slotIndex - device slot.
3914 *
3915 * @return true on success; false on any failure
3916 */
3917 @Override
3918 public boolean rebootModem(int slotIndex) {
3919 Phone phone = PhoneFactory.getPhone(slotIndex);
3920 if (phone != null) {
3921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3922 mApp, phone.getSubId(), "rebootModem");
3923
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3927 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3928 return success;
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
3932 }
3933 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003934 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003935
Svet Ganovb320e182015-04-16 12:30:10 -07003936 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003937 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003939 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003940 return new String[0];
3941 }
3942
Malcolm Chend965c8b2018-02-28 15:00:40 -08003943 final long identity = Binder.clearCallingIdentity();
3944 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003945 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
Wink Saville36469e72014-06-11 15:17:00 -07003949 }
3950
Brad Ebinger51f743a2017-01-23 13:50:20 -08003951 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003952 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3953 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003954 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003955 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003956 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 PhoneFactory.getImsResolver().enableIms(slotId);
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003964 }
3965
3966 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003967 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3968 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003969 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003970 public void disableIms(int slotId) {
3971 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 PhoneFactory.getImsResolver().disableIms(slotId);
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003979 }
3980
3981 /**
3982 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3983 * feature or {@link null} if the service is not available. If the feature is available, the
3984 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3985 */
3986 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003987 IImsServiceFeatureCallback callback) {
3988 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003989
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003996 }
3997
3998 /**
3999 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4000 * feature during emergency calling or {@link null} if the service is not available. If the
4001 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4002 * listener for feature updates.
4003 */
4004 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4005 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006
4007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004013 }
4014
Brad Ebinger5f64b052017-12-14 14:26:15 -08004015 /**
4016 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4017 * specified.
4018 */
4019 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4020 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004028 }
4029
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004030 /**
4031 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4032 * specified.
4033 */
4034 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4035 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004043 }
4044
Brad Ebinger884c07b2018-02-15 16:17:40 -08004045 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004046 * Sets the ImsService Package Name that Telephony will bind to.
4047 *
4048 * @param slotId the slot ID that the ImsService should bind for.
4049 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4050 * ImsService is the device default ImsService.
4051 * @param packageName The package name of the application that contains the ImsService to bind
4052 * to.
4053 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4054 * @hide
4055 */
4056 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004057 int[] subIds = SubscriptionManager.getSubId(slotId);
4058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4059 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4060 "setImsService");
4061
Malcolm Chend965c8b2018-02-28 15:00:40 -08004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4065 isCarrierImsService, packageName);
4066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004069 }
4070
4071 /**
4072 * Return the ImsService configuration.
4073 *
4074 * @param slotId The slot that the ImsService is associated with.
4075 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4076 * the device default.
4077 * @return the package name of the ImsService configuration.
4078 */
4079 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004080 int[] subIds = SubscriptionManager.getSubId(slotId);
4081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4082 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4083 "getImsService");
4084
Malcolm Chend965c8b2018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4088 isCarrierImsService);
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004092 }
4093
Wink Saville36469e72014-06-11 15:17:00 -07004094 public void setImsRegistrationState(boolean registered) {
4095 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004096
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004099 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Wink Saville36469e72014-06-11 15:17:00 -07004103 }
4104
4105 /**
Stuart Scott54788802015-03-30 13:18:01 -07004106 * Set the network selection mode to automatic.
4107 *
4108 */
4109 @Override
4110 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004113
Pengquan Meng466e2482018-09-21 15:54:48 -07004114 if (!isActiveSubscription(subId)) {
4115 return;
4116 }
4117
Malcolm Chend965c8b2018-02-28 15:00:40 -08004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4121 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
Stuart Scott54788802015-03-30 13:18:01 -07004125 }
4126
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004127 /**
4128 * Ask the radio to connect to the input network and change selection mode to manual.
4129 *
4130 * @param subId the id of the subscription.
4131 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4132 * the operator to attach to.
4133 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4134 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4135 * normal network selection next time.
4136 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004137 */
4138 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004139 public boolean setNetworkSelectionModeManual(
4140 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4142 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004143
4144 if (!isActiveSubscription(subId)) {
4145 return false;
4146 }
4147
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004150 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004151 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004152 if (DBG) {
4153 log("setNetworkSelectionModeManual: subId: " + subId
4154 + " operator: " + operatorInfo);
4155 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004156 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004160 }
4161
4162 /**
4163 * Scans for available networks.
4164 */
4165 @Override
4166 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4168 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004169
Pengquan Meng0c05b502018-09-06 09:59:22 -07004170 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004171 try {
4172 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004173 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004174 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004178 }
4179
4180 /**
yinxub1bed742017-04-17 11:45:04 -07004181 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004182 *
yinxub1bed742017-04-17 11:45:04 -07004183 * @param subId id of the subscription
4184 * @param request contains the radio access networks with bands/channels to scan
4185 * @param messenger callback messenger for scan results or errors
4186 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004187 * @return the id of the requested scan which can be used to stop the scan.
4188 */
4189 @Override
4190 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4191 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4193 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004194
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 return mNetworkScanRequestTracker.startNetworkScan(
4198 request, messenger, binder, getPhone(subId));
4199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
yinxu504e1392017-04-12 16:03:22 -07004202 }
4203
4204 /**
4205 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004206 *
4207 * @param subId id of the subscription
4208 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004209 */
4210 @Override
4211 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4213 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004214
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
yinxu504e1392017-04-12 16:03:22 -07004221 }
4222
4223 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004224 * Get the calculated preferred network type.
4225 * Used for debugging incorrect network type.
4226 *
4227 * @return the preferred network type, defined in RILConstants.java.
4228 */
4229 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004230 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004231 final Phone defaultPhone = getDefaultPhone();
4232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4233 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004234 return RILConstants.PREFERRED_NETWORK_MODE;
4235 }
4236
Malcolm Chend965c8b2018-02-28 15:00:40 -08004237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004240 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
Junda Liu84d15a22014-07-02 11:21:04 -07004244 }
4245
4246 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004247 * Get the preferred network type.
4248 * Used for device configuration by some CDMA operators.
4249 *
4250 * @return the preferred network type, defined in RILConstants.java.
4251 */
4252 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004253 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4255 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004256
4257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 if (DBG) log("getPreferredNetworkType");
4260 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4261 int networkType = (result != null ? result[0] : -1);
4262 if (DBG) log("getPreferredNetworkType: " + networkType);
4263 return networkType;
4264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004267 }
4268
4269 /**
4270 * Set the preferred network type.
4271 * Used for device configuration by some CDMA operators.
4272 *
4273 * @param networkType the preferred network type, defined in RILConstants.java.
4274 * @return true on success; false on any failure.
4275 */
4276 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004277 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4279 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4284 Boolean success = (Boolean) sendRequest(
4285 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4286 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4287 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004288 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004289 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4290 }
4291 return success;
4292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004294 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004295 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004296
4297 /**
Junda Liu475951f2014-11-07 16:45:03 -08004298 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004299 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004300 * tethering.
4301 *
4302 * @return 0: Not required. 1: required. 2: Not set.
4303 * @hide
4304 */
4305 @Override
4306 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004307 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004308
4309 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004310 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004311 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004312 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004313 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004314 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004315 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004316 dunRequired = 1;
4317 }
4318 return dunRequired;
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004321 }
Junda Liu475951f2014-11-07 16:45:03 -08004322 }
4323
4324 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004325 * Set mobile data enabled
4326 * Used by the user through settings etc to turn on/off mobile data
4327 *
4328 * @param enable {@code true} turn turn data on, else {@code false}
4329 */
4330 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004331 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4333 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004334
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 int phoneId = mSubscriptionController.getPhoneId(subId);
4338 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4339 Phone phone = PhoneFactory.getPhone(phoneId);
4340 if (phone != null) {
4341 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004342 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004343 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004344 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004345 }
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004348 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004349 }
4350
4351 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004352 * Get the user enabled state of Mobile Data.
4353 *
4354 * TODO: remove and use isUserDataEnabled.
4355 * This can't be removed now because some vendor codes
4356 * calls through ITelephony directly while they should
4357 * use TelephonyManager.
4358 *
4359 * @return true on enabled
4360 */
4361 @Override
4362 public boolean getDataEnabled(int subId) {
4363 return isUserDataEnabled(subId);
4364 }
4365
4366 /**
4367 * Get whether mobile data is enabled per user setting.
4368 *
4369 * There are other factors deciding whether mobile data is actually enabled, but they are
4370 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004371 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004372 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004373 *
4374 * @return {@code true} if data is enabled else {@code false}
4375 */
4376 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004377 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004378 try {
4379 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4380 null);
4381 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4383 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004384 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004385
4386 final long identity = Binder.clearCallingIdentity();
4387 try {
4388 int phoneId = mSubscriptionController.getPhoneId(subId);
4389 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4390 Phone phone = PhoneFactory.getPhone(phoneId);
4391 if (phone != null) {
4392 boolean retVal = phone.isUserDataEnabled();
4393 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4394 return retVal;
4395 } else {
4396 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4397 return false;
4398 }
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004401 }
4402 }
4403
4404 /**
4405 * Get whether mobile data is enabled.
4406 *
4407 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4408 * whether mobile data is actually enabled.
4409 *
4410 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4411 *
4412 * @return {@code true} if data is enabled else {@code false}
4413 */
4414 @Override
4415 public boolean isDataEnabled(int subId) {
4416 try {
4417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4418 null);
4419 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4421 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004422 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004423
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 int phoneId = mSubscriptionController.getPhoneId(subId);
4427 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4428 Phone phone = PhoneFactory.getPhone(phoneId);
4429 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004430 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004431 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4432 return retVal;
4433 } else {
4434 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4435 return false;
4436 }
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004439 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004440 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004441
4442 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004443 public int getCarrierPrivilegeStatus(int subId) {
4444 final Phone phone = getPhone(subId);
4445 if (phone == null) {
4446 loge("getCarrierPrivilegeStatus: Invalid subId");
4447 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4448 }
4449 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004450 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004451 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004452 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4453 }
4454 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004455 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004456 }
Junda Liu29340342014-07-10 15:23:27 -07004457
4458 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004459 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4460 final Phone phone = getPhone(subId);
4461 if (phone == null) {
4462 loge("getCarrierPrivilegeStatus: Invalid subId");
4463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4464 }
4465 UiccProfile profile =
4466 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4467 if (profile == null) {
4468 loge("getCarrierPrivilegeStatus: No UICC");
4469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4470 }
4471 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4472 }
4473
4474 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004475 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004476 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004477 if (TextUtils.isEmpty(pkgName))
4478 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004479 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004480 if (card == null) {
4481 loge("checkCarrierPrivilegesForPackage: No UICC");
4482 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4483 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004484 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4485 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004486 }
4487
4488 @Override
4489 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004490 if (TextUtils.isEmpty(pkgName))
4491 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004492 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4493 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4494 UiccCard card = UiccController.getInstance().getUiccCard(i);
4495 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004496 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004497 continue;
4498 }
4499
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004500 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004501 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4502 break;
4503 }
4504 }
4505
4506 return result;
Junda Liu29340342014-07-10 15:23:27 -07004507 }
Derek Tan89e89d42014-07-08 17:00:10 -07004508
4509 @Override
Junda Liue64de782015-04-16 17:19:16 -07004510 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4511 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4512 loge("phoneId " + phoneId + " is not valid.");
4513 return null;
4514 }
4515 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004516 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004517 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004518 return null ;
4519 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004520 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004521 }
4522
Amith Yamasani6e118872016-02-19 12:53:51 -08004523 @Override
4524 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004525 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004526 List<String> privilegedPackages = new ArrayList<>();
4527 List<PackageInfo> packages = null;
4528 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4529 UiccCard card = UiccController.getInstance().getUiccCard(i);
4530 if (card == null) {
4531 // No UICC in that slot.
4532 continue;
4533 }
4534 if (card.hasCarrierPrivilegeRules()) {
4535 if (packages == null) {
4536 // Only check packages in user 0 for now
4537 packages = pm.getInstalledPackagesAsUser(
4538 PackageManager.MATCH_DISABLED_COMPONENTS
4539 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4540 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4541 }
4542 for (int p = packages.size() - 1; p >= 0; p--) {
4543 PackageInfo pkgInfo = packages.get(p);
4544 if (pkgInfo != null && pkgInfo.packageName != null
4545 && card.getCarrierPrivilegeStatus(pkgInfo)
4546 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4547 privilegedPackages.add(pkgInfo.packageName);
4548 }
4549 }
4550 }
4551 }
4552 return privilegedPackages;
4553 }
4554
Wink Savilleb564aae2014-10-23 10:18:09 -07004555 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004556 final Phone phone = getPhone(subId);
4557 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004558 if (card == null) {
4559 loge("getIccId: No UICC");
4560 return null;
4561 }
4562 String iccId = card.getIccId();
4563 if (TextUtils.isEmpty(iccId)) {
4564 loge("getIccId: ICC ID is null or empty.");
4565 return null;
4566 }
4567 return iccId;
4568 }
4569
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004570 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004571 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4572 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004573 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4574 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004575
Malcolm Chend965c8b2018-02-28 15:00:40 -08004576 final long identity = Binder.clearCallingIdentity();
4577 try {
4578 final String iccId = getIccId(subId);
4579 final Phone phone = getPhone(subId);
4580 if (phone == null) {
4581 return false;
4582 }
4583 final String subscriberId = phone.getSubscriberId();
4584
4585 if (DBG_MERGE) {
4586 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4587 + subscriberId + " to " + number);
4588 }
4589
4590 if (TextUtils.isEmpty(iccId)) {
4591 return false;
4592 }
4593
4594 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4595
4596 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4597 if (alphaTag == null) {
4598 editor.remove(alphaTagPrefKey);
4599 } else {
4600 editor.putString(alphaTagPrefKey, alphaTag);
4601 }
4602
4603 // Record both the line number and IMSI for this ICCID, since we need to
4604 // track all merged IMSIs based on line number
4605 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4606 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4607 if (number == null) {
4608 editor.remove(numberPrefKey);
4609 editor.remove(subscriberPrefKey);
4610 } else {
4611 editor.putString(numberPrefKey, number);
4612 editor.putString(subscriberPrefKey, subscriberId);
4613 }
4614
4615 editor.commit();
4616 return true;
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004619 }
Derek Tan7226c842014-07-02 17:42:23 -07004620 }
4621
4622 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004623 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004624 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004626 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004627 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004628 return null;
4629 }
Derek Tan97ebb422014-09-05 16:55:38 -07004630
Malcolm Chend965c8b2018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 String iccId = getIccId(subId);
4634 if (iccId != null) {
4635 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4636 if (DBG_MERGE) {
4637 log("getLine1NumberForDisplay returning "
4638 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4639 }
4640 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004641 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004642 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4643 return null;
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004646 }
Derek Tan7226c842014-07-02 17:42:23 -07004647 }
4648
4649 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004650 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004652 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004653 return null;
4654 }
Derek Tan97ebb422014-09-05 16:55:38 -07004655
Malcolm Chend965c8b2018-02-28 15:00:40 -08004656 final long identity = Binder.clearCallingIdentity();
4657 try {
4658 String iccId = getIccId(subId);
4659 if (iccId != null) {
4660 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4661 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4662 }
4663 return null;
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004666 }
Derek Tan7226c842014-07-02 17:42:23 -07004667 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004668
4669 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004670 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004671 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4672 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004674 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4675 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004676 return null;
4677 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004678
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004679 final long identity = Binder.clearCallingIdentity();
4680 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004681 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004682 final TelephonyManager tele = TelephonyManager.from(context);
4683 final SubscriptionManager sub = SubscriptionManager.from(context);
4684
4685 // Figure out what subscribers are currently active
4686 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4687 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4688 // the process, where TelephonyManager was instantiated.
4689 // Otherwise AppOps check will fail.
4690
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004691 final int[] subIds = sub.getActiveSubscriptionIdList();
4692 for (int subId : subIds) {
4693 activeSubscriberIds.add(tele.getSubscriberId(subId));
4694 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004695
4696 // First pass, find a number override for an active subscriber
4697 String mergeNumber = null;
4698 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4699 for (String key : prefs.keySet()) {
4700 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4701 final String subscriberId = (String) prefs.get(key);
4702 if (activeSubscriberIds.contains(subscriberId)) {
4703 final String iccId = key.substring(
4704 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4705 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4706 mergeNumber = (String) prefs.get(numberKey);
4707 if (DBG_MERGE) {
4708 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4709 + " for active subscriber " + subscriberId);
4710 }
4711 if (!TextUtils.isEmpty(mergeNumber)) {
4712 break;
4713 }
4714 }
4715 }
4716 }
4717
4718 // Shortcut when no active merged subscribers
4719 if (TextUtils.isEmpty(mergeNumber)) {
4720 return null;
4721 }
4722
4723 // Second pass, find all subscribers under that line override
4724 final ArraySet<String> result = new ArraySet<>();
4725 for (String key : prefs.keySet()) {
4726 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4727 final String number = (String) prefs.get(key);
4728 if (mergeNumber.equals(number)) {
4729 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4730 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4731 final String subscriberId = (String) prefs.get(subscriberKey);
4732 if (!TextUtils.isEmpty(subscriberId)) {
4733 result.add(subscriberId);
4734 }
4735 }
4736 }
4737 }
4738
4739 final String[] resultArray = result.toArray(new String[result.size()]);
4740 Arrays.sort(resultArray);
4741 if (DBG_MERGE) {
4742 Slog.d(LOG_TAG,
4743 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4744 }
4745 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004748 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004749 }
4750
4751 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004752 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004753 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4754 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004755
4756 final long identity = Binder.clearCallingIdentity();
4757 try {
4758 final Phone phone = getPhone(subId);
4759 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004763 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004764
4765 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004766 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004767 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4768 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004770
4771 final long identity = Binder.clearCallingIdentity();
4772 try {
4773 final Phone phone = getPhone(subId);
4774 if (phone == null) {
4775 return false;
4776 }
4777 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4778 cdmaNonRoamingList);
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004781 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004782 }
4783
4784 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004785 @Deprecated
4786 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4787 enforceModifyPermission();
4788
4789 int returnValue = 0;
4790 try {
vagdevie435a3e2018-08-15 16:01:53 -07004791 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004792 if(result.exception == null) {
4793 if (result.result != null) {
4794 byte[] responseData = (byte[])(result.result);
4795 if(responseData.length > oemResp.length) {
4796 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4797 responseData.length + "bytes. Buffer Size is " +
4798 oemResp.length + "bytes.");
4799 }
4800 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4801 returnValue = responseData.length;
4802 }
4803 } else {
4804 CommandException ex = (CommandException) result.exception;
4805 returnValue = ex.getCommandError().ordinal();
4806 if(returnValue > 0) returnValue *= -1;
4807 }
4808 } catch (RuntimeException e) {
4809 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4810 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4811 if(returnValue > 0) returnValue *= -1;
4812 }
4813
4814 return returnValue;
4815 }
4816
4817 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004818 public void setRadioCapability(RadioAccessFamily[] rafs) {
4819 try {
4820 ProxyController.getInstance().setRadioCapability(rafs);
4821 } catch (RuntimeException e) {
4822 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4823 }
4824 }
4825
4826 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004827 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004828 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004829 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004830 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004831 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004832 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
chen xufeeed752018-10-26 14:17:57 -07004835 TelephonyPermissions
4836 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4837 mApp, phone.getSubId(), "getRadioAccessFamily");
4838 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004839 } finally {
4840 Binder.restoreCallingIdentity(identity);
4841 }
chen xufeeed752018-10-26 14:17:57 -07004842 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004843 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004844
4845 @Override
4846 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004847 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004848 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004852 ImsManager.getInstance(defaultPhone.getContext(),
4853 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004857 }
4858
4859 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004860 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004861 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004863 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004864 return false;
4865 }
Svet Ganovb320e182015-04-16 12:30:10 -07004866
Malcolm Chend965c8b2018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 // Check the user preference and the system-level IMS setting. Even if the user has
4870 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4871 // In the long run, we may instead need to check if there exists a connection service
4872 // which can support video calling.
4873 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004874 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004875 return imsManager.isVtEnabledByPlatform()
4876 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4877 && imsManager.isVtEnabledByUser();
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004881 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004882
Andrew Leea1239f22015-03-02 17:44:07 -08004883 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004884 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4886 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4887 return false;
4888 }
4889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 CarrierConfigManager configManager =
4893 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004894 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004895 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
Andrew Leea1239f22015-03-02 17:44:07 -08004899 }
4900
4901 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004902 public boolean isWorldPhone(int subId, String callingPackage) {
4903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4904 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4905 return false;
4906 }
4907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 CarrierConfigManager configManager =
4911 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004912 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004913 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
Andrew Leea1239f22015-03-02 17:44:07 -08004917 }
4918
Andrew Lee9431b832015-03-09 18:46:45 -07004919 @Override
4920 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004921 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004922 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004923 }
4924
4925 @Override
4926 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004929 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
Andrew Lee9431b832015-03-09 18:46:45 -07004933 }
4934
Hall Liuf6668912018-10-31 17:05:23 -07004935 /**
4936 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4937 * support for the feature and device firmware support.
4938 *
4939 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4940 */
4941 @Override
4942 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004943 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004944 final Phone phone = getPhone(subscriptionId);
4945 if (phone == null) {
4946 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4947 return false;
4948 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004949 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004950 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004951 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4952 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004953 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004954 return isCarrierSupported && isDeviceSupported;
4955 } finally {
4956 Binder.restoreCallingIdentity(identity);
4957 }
Hall Liu98187582018-01-22 19:15:32 -08004958 }
4959
Hall Liuf6668912018-10-31 17:05:23 -07004960 /**
4961 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4962 * both also support RTT.
4963 */
4964 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004965 final long identity = Binder.clearCallingIdentity();
4966 try {
Hall Liuf6668912018-10-31 17:05:23 -07004967 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004968 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004972 }
4973
Sanket Padawe7310cc72015-01-14 09:53:20 -08004974 /**
4975 * Returns the unique device ID of phone, for example, the IMEI for
4976 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4977 *
4978 * <p>Requires Permission:
4979 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4980 */
4981 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004982 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004983 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004985 return null;
4986 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004987 int subId = phone.getSubId();
4988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4989 mApp, subId, callingPackage, "getDeviceId")) {
4990 return null;
4991 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004992
4993 final long identity = Binder.clearCallingIdentity();
4994 try {
4995 return phone.getDeviceId();
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004999 }
5000
Ping Sunc67b7c22016-03-02 19:16:45 +08005001 /**
5002 * {@hide}
5003 * Returns the IMS Registration Status on a particular subid
5004 *
5005 * @param subId
5006 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005007 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005008 Phone phone = getPhone(subId);
5009 if (phone != null) {
5010 return phone.isImsRegistered();
5011 } else {
5012 return false;
5013 }
5014 }
5015
Santos Cordon7a1885b2015-02-03 11:15:19 -08005016 @Override
5017 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005024 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005025
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005026 /**
5027 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005028 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005029 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005030 final long identity = Binder.clearCallingIdentity();
5031 try {
5032 Phone phone = getPhone(subId);
5033 if (phone != null) {
5034 return phone.isWifiCallingEnabled();
5035 } else {
5036 return false;
5037 }
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005040 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005041 }
5042
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005043 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005044 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005045 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005046 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 Phone phone = getPhone(subId);
5050 if (phone != null) {
5051 return phone.isVideoEnabled();
5052 } else {
5053 return false;
5054 }
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005057 }
5058 }
5059
5060 /**
5061 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5062 * defined in {@link ImsRegistrationImplBase}.
5063 */
5064 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 Phone phone = getPhone(subId);
5068 if (phone != null) {
5069 return phone.getImsRegistrationTech();
5070 } else {
5071 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5072 }
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005075 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005076 }
5077
Stuart Scott8eef64f2015-04-08 15:13:54 -07005078 @Override
5079 public void factoryReset(int subId) {
5080 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005081 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5082 return;
5083 }
5084
Svet Ganovcc087f82015-05-12 20:35:54 -07005085 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005086
Svet Ganovcc087f82015-05-12 20:35:54 -07005087 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005088 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5089 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005090 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005091 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005092 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005093 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5094 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005095 }
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005098 }
5099 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005100
5101 @Override
5102 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005103 final long identity = Binder.clearCallingIdentity();
5104 try {
5105 // We query all subscriptions instead of just the active ones, because
5106 // this might be called early on in the provisioning flow when the
5107 // subscriptions potentially aren't active yet.
5108 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
5109 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01005110 return null;
5111 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005112
Malcolm Chend965c8b2018-02-28 15:00:40 -08005113 // This function may be called very early, say, from the setup wizard, at
5114 // which point we won't have a default subscription set. If that's the case
5115 // we just choose the first, which will be valid in "most cases".
5116 final int defaultSubId = getDefaultSubscription();
5117 SubscriptionInfo info = null;
5118 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5119 info = slist.get(0);
5120 } else {
5121 for (SubscriptionInfo item : slist) {
5122 if (item.getSubscriptionId() == defaultSubId) {
5123 info = item;
5124 break;
5125 }
5126 }
5127
5128 if (info == null) {
5129 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01005130 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005131 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005132
Malcolm Chend965c8b2018-02-28 15:00:40 -08005133 // Try and fetch the locale from the carrier properties or from the SIM language
5134 // preferences (EF-PL and EF-LI)...
5135 final int mcc = info.getMcc();
5136 final Phone defaultPhone = getPhone(info.getSubscriptionId());
5137 String simLanguage = null;
5138 if (defaultPhone != null) {
5139 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
5140 if (localeFromDefaultSim != null) {
5141 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5142 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
5143 return localeFromDefaultSim.toLanguageTag();
5144 } else {
5145 simLanguage = localeFromDefaultSim.getLanguage();
5146 }
5147 }
5148 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005149
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150 // The SIM language preferences only store a language (e.g. fr = French), not an
5151 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5152 // the SIM and carrier preferences does not include a country we add the country
5153 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005154 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005155 if (mccLocale != null) {
5156 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
5157 return mccLocale.toLanguageTag();
5158 }
5159
5160 if (DBG) log("No locale found - returning null");
5161 return null;
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
5164 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005165 }
5166
5167 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005168 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005169 }
5170
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 /**
5172 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5173 */
5174 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005175 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005176 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005177
Chenjie Yu1ba97252018-01-11 18:16:20 -08005178 private final ModemActivityInfo mLastModemActivityInfo =
5179 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5180
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005181 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005182 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5183 * representing the state of the modem.
5184 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005185 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5186 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005187 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005188 */
5189 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005190 public void requestModemActivityInfo(ResultReceiver result) {
5191 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 ModemActivityInfo ret = null;
5197 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005198 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5199 CMD_GET_MODEM_ACTIVITY_INFO,
5200 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005201 if (isModemActivityInfoValid(info)) {
5202 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5203 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5204 mergedTxTimeMs[i] =
5205 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5206 }
5207 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5208 mLastModemActivityInfo.setSleepTimeMillis(
5209 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5210 mLastModemActivityInfo.setIdleTimeMillis(
5211 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5212 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5213 mLastModemActivityInfo.setRxTimeMillis(
5214 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5215 mLastModemActivityInfo.setEnergyUsed(
5216 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005217 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5219 mLastModemActivityInfo.getSleepTimeMillis(),
5220 mLastModemActivityInfo.getIdleTimeMillis(),
5221 mLastModemActivityInfo.getTxTimeMillis(),
5222 mLastModemActivityInfo.getRxTimeMillis(),
5223 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005224 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005225 Bundle bundle = new Bundle();
5226 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5227 result.send(0, bundle);
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005230 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005231 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005232
Siddharth Rayf5d29552018-06-17 15:02:38 -07005233 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5234 // less than total activity duration.
5235 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5236 if (info == null) {
5237 return false;
5238 }
5239 int activityDurationMs =
5240 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5241 int totalTxTimeMs = 0;
5242 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5243 totalTxTimeMs += info.getTxTimeMillis()[i];
5244 }
5245 return (info.isValid()
5246 && (info.getSleepTimeMillis() <= activityDurationMs)
5247 && (info.getIdleTimeMillis() <= activityDurationMs)
5248 && (info.getRxTimeMillis() <= activityDurationMs)
5249 && (totalTxTimeMs <= activityDurationMs));
5250 }
5251
Jack Yu85bd38a2015-11-09 11:34:32 -08005252 /**
5253 * {@hide}
5254 * Returns the service state information on specified subscription.
5255 */
5256 @Override
5257 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005259 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005260 return null;
5261 }
5262
Malcolm Chend965c8b2018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 final Phone phone = getPhone(subId);
5266 if (phone == null) {
5267 return null;
5268 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005269
Malcolm Chend965c8b2018-02-28 15:00:40 -08005270 return phone.getServiceState();
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005274 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005275
5276 /**
5277 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5278 *
5279 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5280 * voicemail ringtone.
5281 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5282 * PhoneAccount.
5283 */
5284 @Override
5285 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5289 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005290 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005291 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005292
Malcolm Chend965c8b2018-02-28 15:00:40 -08005293 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005297 }
5298
5299 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005300 * Sets the per-account voicemail ringtone.
5301 *
5302 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5303 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5304 *
5305 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5306 * voicemail ringtone.
5307 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5308 * PhoneAccount.
5309 */
5310 @Override
5311 public void setVoicemailRingtoneUri(String callingPackage,
5312 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005313 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5315 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005316 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5319 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005320 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005321
5322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5325 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005326 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005327 }
5328 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005331 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005332 }
5333
5334 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005335 * Returns whether vibration is set for voicemail notification in Phone settings.
5336 *
5337 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5338 * voicemail vibration setting.
5339 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5340 */
5341 @Override
5342 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5346 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005347 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005348 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005349
Malcolm Chend965c8b2018-02-28 15:00:40 -08005350 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005354 }
5355
Youhan Wange64578a2016-05-02 15:32:42 -07005356 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005357 * Sets the per-account voicemail vibration.
5358 *
5359 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5360 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5361 *
5362 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5363 * voicemail vibration setting.
5364 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5365 * specific PhoneAccount.
5366 */
5367 @Override
5368 public void setVoicemailVibrationEnabled(String callingPackage,
5369 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005370 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5372 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005373 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5375 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5376 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005377 }
5378
Malcolm Chend965c8b2018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5382 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005383 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005384 }
5385 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005388 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005389 }
5390
5391 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005392 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5393 *
5394 * @throws SecurityException if the caller does not have the required permission
5395 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005396 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005397 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005398 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005399 }
5400
5401 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005402 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5403 * permission.
5404 *
5405 * @throws SecurityException if the caller does not have the required permission
5406 */
5407 private void enforceSendSmsPermission() {
5408 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5409 }
5410
5411 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005412 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005413 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005414 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005415 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005416 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005420 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005421 if (componentName == null) {
5422 throw new SecurityException(
5423 "Caller not current active visual voicemail package[null]");
5424 }
5425 String vvmPackage = componentName.getPackageName();
5426 if (!callingPackage.equals(vvmPackage)) {
5427 throw new SecurityException("Caller not current active visual voicemail package["
5428 + vvmPackage + "]");
5429 }
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005432 }
5433 }
5434
5435 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005436 * Return the application ID for the app type.
5437 *
5438 * @param subId the subscription ID that this request applies to.
5439 * @param appType the uicc app type.
5440 * @return Application ID for specificied app type, or null if no uicc.
5441 */
5442 @Override
5443 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005444 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005445 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005446
5447 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005448 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005449 if (phone == null) {
5450 return null;
5451 }
5452 String aid = null;
5453 try {
5454 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5455 .getApplicationByType(appType).getAid();
5456 } catch (Exception e) {
5457 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5458 }
5459 return aid;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005462 }
Youhan Wange64578a2016-05-02 15:32:42 -07005463 }
5464
Youhan Wang4001d252016-05-11 10:29:41 -07005465 /**
5466 * Return the Electronic Serial Number.
5467 *
5468 * @param subId the subscription ID that this request applies to.
5469 * @return ESN or null if error.
5470 */
5471 @Override
5472 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005473 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005474 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005477 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478 if (phone == null) {
5479 return null;
5480 }
5481 String esn = null;
5482 try {
5483 esn = phone.getEsn();
5484 } catch (Exception e) {
5485 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5486 }
5487 return esn;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005490 }
Youhan Wang4001d252016-05-11 10:29:41 -07005491 }
5492
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005493 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005494 * Return the Preferred Roaming List Version.
5495 *
5496 * @param subId the subscription ID that this request applies to.
5497 * @return PRLVersion or null if error.
5498 */
5499 @Override
5500 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005501 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005502 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005503
5504 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005505 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005506 if (phone == null) {
5507 return null;
5508 }
5509 String cdmaPrlVersion = null;
5510 try {
5511 cdmaPrlVersion = phone.getCdmaPrlVersion();
5512 } catch (Exception e) {
5513 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5514 }
5515 return cdmaPrlVersion;
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005518 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005519 }
5520
5521 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005522 * Get snapshot of Telephony histograms
5523 * @return List of Telephony histograms
5524 * @hide
5525 */
5526 @Override
5527 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 return RIL.getTelephonyRILTimingHistograms();
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005537 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005538
5539 /**
5540 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005541 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5542 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005543 * Require system privileges. In the future we may add this to carrier APIs.
5544 *
Michele Berionne0963c862018-11-27 18:57:59 -08005545 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005546 */
5547 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005548 @TelephonyManager.SetCarrierRestrictionResult
5549 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005550 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005552
Michele Berionne0963c862018-11-27 18:57:59 -08005553 if (carrierRestrictionRules == null) {
5554 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005555 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005556
Malcolm Chend965c8b2018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005559 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005560 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005564 }
5565
5566 /**
5567 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005568 * Get the allowed carrier list and the excluded carrier list, including the priority between
5569 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005570 * Require system privileges. In the future we may add this to carrier APIs.
5571 *
Michele Berionne0963c862018-11-27 18:57:59 -08005572 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005573 */
5574 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005575 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005576 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005581 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5582 if (response instanceof CarrierRestrictionRules) {
5583 return (CarrierRestrictionRules) response;
5584 }
5585 // Response is an Exception of some kind,
5586 // which is signalled to the user as a NULL retval
5587 return null;
5588 } catch (Exception e) {
5589 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5590 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005594 }
5595
fionaxu59545b42016-05-25 15:53:37 -07005596 /**
5597 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5598 * @param subId the subscription ID that this action applies to.
5599 * @param enabled control enable or disable metered apns.
5600 * {@hide}
5601 */
5602 @Override
5603 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5604 enforceModifyPermission();
5605 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005606
5607 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005608 if (phone == null) {
5609 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5610 return;
5611 }
5612 try {
5613 phone.carrierActionSetMeteredApnsEnabled(enabled);
5614 } catch (Exception e) {
5615 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005616 } finally {
5617 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005618 }
5619 }
5620
5621 /**
5622 * Action set from carrier signalling broadcast receivers to enable/disable radio
5623 * @param subId the subscription ID that this action applies to.
5624 * @param enabled control enable or disable radio.
5625 * {@hide}
5626 */
5627 @Override
5628 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5629 enforceModifyPermission();
5630 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005633 if (phone == null) {
5634 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5635 return;
5636 }
5637 try {
5638 phone.carrierActionSetRadioEnabled(enabled);
5639 } catch (Exception e) {
5640 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005643 }
5644 }
5645
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005646 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005647 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5648 * network status based on which carrier apps could apply actions accordingly,
5649 * enable/disable default url handler for example.
5650 *
5651 * @param subId the subscription ID that this action applies to.
5652 * @param report control start/stop reporting the default network status.
5653 * {@hide}
5654 */
5655 @Override
5656 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5657 enforceModifyPermission();
5658 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005661 if (phone == null) {
5662 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5663 return;
5664 }
5665 try {
5666 phone.carrierActionReportDefaultNetworkStatus(report);
5667 } catch (Exception e) {
5668 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005669 } finally {
5670 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005671 }
5672 }
5673
5674 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005675 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5676 * bug report is being generated.
5677 */
5678 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005679 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005680 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5681 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005682 writer.println("Permission Denial: can't dump Phone from pid="
5683 + Binder.getCallingPid()
5684 + ", uid=" + Binder.getCallingUid()
5685 + "without permission "
5686 + android.Manifest.permission.DUMP);
5687 return;
5688 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005689 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005690 }
Jack Yueb89b242016-06-22 13:27:47 -07005691
Brad Ebingerdac2f002018-04-03 15:17:52 -07005692 @Override
5693 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5694 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5695 throws RemoteException {
5696 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5697 }
5698
Jack Yueb89b242016-06-22 13:27:47 -07005699 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005700 * Get aggregated video call data usage since boot.
5701 *
5702 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5703 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005704 * {@hide}
5705 */
5706 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005707 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5709 null);
5710
Malcolm Chend965c8b2018-02-28 15:00:40 -08005711 final long identity = Binder.clearCallingIdentity();
5712 try {
5713 // NetworkStatsService keeps tracking the active network interface and identity. It
5714 // records the delta with the corresponding network identity.
5715 // We just return the total video call data usage snapshot since boot.
5716 Phone phone = getPhone(subId);
5717 if (phone != null) {
5718 return phone.getVtDataUsage(perUidStats);
5719 }
5720 return null;
5721 } finally {
5722 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005723 }
Jack Yueb89b242016-06-22 13:27:47 -07005724 }
Jack Yu75ab2952016-07-08 14:29:33 -07005725
5726 /**
5727 * Policy control of data connection. Usually used when data limit is passed.
5728 * @param enabled True if enabling the data, otherwise disabling.
5729 * @param subId Subscription index
5730 * {@hide}
5731 */
5732 @Override
5733 public void setPolicyDataEnabled(boolean enabled, int subId) {
5734 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 Phone phone = getPhone(subId);
5739 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005740 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005741 }
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005744 }
5745 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005746
5747 /**
5748 * Get Client request stats
5749 * @return List of Client Request Stats
5750 * @hide
5751 */
5752 @Override
5753 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005755 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005756 return null;
5757 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005758 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005759
Malcolm Chend965c8b2018-02-28 15:00:40 -08005760 final long identity = Binder.clearCallingIdentity();
5761 try {
5762 if (phone != null) {
5763 return phone.getClientRequestStats();
5764 }
5765
5766 return null;
5767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005770 }
5771
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005772 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005773 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005774 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005775 }
Jack Yueb4124c2017-02-16 15:32:43 -08005776
5777 /**
Grace Chen70990072017-03-24 17:21:30 -07005778 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005779 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005780 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005781 * @param state State of SIM (power down, power up, pass through)
5782 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5783 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5784 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005785 *
5786 **/
5787 @Override
Grace Chen70990072017-03-24 17:21:30 -07005788 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005789 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005790 Phone phone = PhoneFactory.getPhone(slotIndex);
5791
vagdevie435a3e2018-08-15 16:01:53 -07005792 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5793
Malcolm Chend965c8b2018-02-28 15:00:40 -08005794 final long identity = Binder.clearCallingIdentity();
5795 try {
5796 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005797 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005798 }
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005801 }
5802 }
Shuo Qiandd210312017-04-12 22:11:33 +00005803
Tyler Gunn65d45c22017-06-05 11:22:26 -07005804 private boolean isUssdApiAllowed(int subId) {
5805 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005806 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005807 if (configManager == null) {
5808 return false;
5809 }
5810 PersistableBundle pb = configManager.getConfigForSubId(subId);
5811 if (pb == null) {
5812 return false;
5813 }
5814 return pb.getBoolean(
5815 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5816 }
5817
Shuo Qiandd210312017-04-12 22:11:33 +00005818 /**
5819 * Check if phone is in emergency callback mode
5820 * @return true if phone is in emergency callback mode
5821 * @param subId sub id
5822 */
goneil9c5f4872017-12-05 14:07:56 -08005823 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005824 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005825 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005826 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005827
5828 final long identity = Binder.clearCallingIdentity();
5829 try {
5830 if (phone != null) {
5831 return phone.isInEcm();
5832 } else {
5833 return false;
5834 }
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005837 }
5838 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005839
5840 /**
5841 * Get the current signal strength information for the given subscription.
5842 * Because this information is not updated when the device is in a low power state
5843 * it should not be relied-upon to be current.
5844 * @param subId Subscription index
5845 * @return the most recent cached signal strength info from the modem
5846 */
5847 @Override
5848 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 Phone p = getPhone(subId);
5852 if (p == null) {
5853 return null;
5854 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005855
Malcolm Chend965c8b2018-02-28 15:00:40 -08005856 return p.getSignalStrength();
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005860 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005861
Pengquan Meng9140aec2018-08-22 14:49:57 -07005862 /**
chen xu907e5a22018-10-11 13:21:04 -07005863 * Get the current modem radio state for the given slot.
5864 * @param slotIndex slot index.
5865 * @param callingPackage the name of the package making the call.
5866 * @return the current radio power state from the modem
5867 */
5868 @Override
5869 public int getRadioPowerState(int slotIndex, String callingPackage) {
5870 Phone phone = PhoneFactory.getPhone(slotIndex);
5871 if (phone != null) {
5872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5873 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5874 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5875 }
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 return phone.getRadioPowerState();
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
5883 }
5884 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5885 }
5886
5887 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005888 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5889 *
5890 * <p>Requires one of the following permissions:
5891 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5892 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5893 * privileges.
5894 *
5895 * @param subId subscription id
5896 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5897 * {@code false}.
5898 */
5899 @Override
5900 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005901 boolean isEnabled = false;
5902 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005903 try {
5904 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005905 null /* message */);
5906 Phone phone = getPhone(subId);
5907 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005908 } catch (Exception e) {
5909 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5910 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005911 } finally {
5912 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005913 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005914 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005915 }
5916
5917
5918 /**
5919 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5920 *
5921 * <p> Requires permission:
5922 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5923 * privileges.
5924 *
5925 * @param subId subscription id
5926 * @param isEnabled {@code true} means enable, {@code false} means disable.
5927 */
5928 @Override
5929 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5933 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005934
Pengquan Meng0c05b502018-09-06 09:59:22 -07005935 Phone phone = getPhone(subId);
5936 if (phone != null) {
5937 phone.setDataRoamingEnabled(isEnabled);
5938 }
5939 } finally {
5940 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005941 }
5942 }
5943
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005944 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005945 public boolean isManualNetworkSelectionAllowed(int subId) {
5946 boolean isAllowed = true;
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5950 mApp, subId, "isManualNetworkSelectionAllowed");
5951 Phone phone = getPhone(subId);
5952 if (phone != null) {
5953 isAllowed = phone.isCspPlmnEnabled();
5954 }
5955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
5958 return isAllowed;
5959 }
5960
5961 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005962 public UiccCardInfo[] getUiccCardsInfo() {
5963 enforceReadPrivilegedPermission("getUiccCardsInfo");
5964
5965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5968 return cards.toArray(new UiccCardInfo[cards.size()]);
5969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
5972 }
5973
5974 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005975 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005976 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005977
Malcolm Chend965c8b2018-02-28 15:00:40 -08005978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5981 if (slots == null) {
5982 Rlog.i(LOG_TAG, "slots is null.");
5983 return null;
5984 }
5985
5986 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5987 for (int i = 0; i < slots.length; i++) {
5988 UiccSlot slot = slots[i];
5989 if (slot == null) {
5990 continue;
5991 }
5992
5993 String cardId;
5994 UiccCard card = slot.getUiccCard();
5995 if (card != null) {
5996 cardId = card.getCardId();
5997 } else {
5998 cardId = slot.getIccId();
5999 }
6000
6001 int cardState = 0;
6002 switch (slot.getCardState()) {
6003 case CARDSTATE_ABSENT:
6004 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6005 break;
6006 case CARDSTATE_PRESENT:
6007 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6008 break;
6009 case CARDSTATE_ERROR:
6010 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6011 break;
6012 case CARDSTATE_RESTRICTED:
6013 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6014 break;
6015 default:
6016 break;
6017
6018 }
6019
6020 infos[i] = new UiccSlotInfo(
6021 slot.isActive(),
6022 slot.isEuicc(),
6023 cardId,
6024 cardState,
6025 slot.getPhoneId(),
6026 slot.isExtendedApduSupported());
6027 }
6028 return infos;
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006031 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006032 }
6033
6034 @Override
6035 public boolean switchSlots(int[] physicalSlots) {
6036 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006037
6038 final long identity = Binder.clearCallingIdentity();
6039 try {
6040 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006044 }
Jack Yu4c988042018-02-27 15:30:01 -08006045
6046 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006047 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
6048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6049 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
6050 return TelephonyManager.INVALID_CARD_ID;
6051 }
6052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 return UiccController.getInstance().getCardIdForDefaultEuicc();
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
6060
6061 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006062 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6063 enforceModifyPermission();
6064 final Phone phone = getPhone(subId);
6065 if (phone == null) {
6066 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6067 return;
6068 }
6069
Malcolm Chend965c8b2018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 phone.setRadioIndicationUpdateMode(filters, mode);
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
Jack Yu4c988042018-02-27 15:30:01 -08006076 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006077
6078 /**
goneil47ffb6e2018-04-06 15:40:58 -07006079 * A test API to reload the UICC profile.
6080 *
6081 * <p>Requires that the calling app has permission
6082 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6083 * @hide
6084 */
6085 @Override
6086 public void refreshUiccProfile(int subId) {
6087 enforceModifyPermission();
6088
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 Phone phone = getPhone(subId);
6092 if (phone == null) {
6093 return;
6094 }
6095 UiccCard uiccCard = phone.getUiccCard();
6096 if (uiccCard == null) {
6097 return;
6098 }
6099 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6100 if (uiccProfile == null) {
6101 return;
6102 }
6103 uiccProfile.refresh();
6104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
6107 }
6108
6109 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006110 * Returns false if the mobile data is disabled by default, otherwise return true.
6111 */
6112 private boolean getDefaultDataEnabled() {
6113 return "true".equalsIgnoreCase(
6114 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6115 }
6116
6117 /**
6118 * Returns true if the data roaming is enabled by default, i.e the system property
6119 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6120 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6121 */
6122 private boolean getDefaultDataRoamingEnabled(int subId) {
6123 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006124 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006125 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6126 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6127 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6128 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6129 return isDataRoamingEnabled;
6130 }
6131
6132 /**
6133 * Returns the default network type for the given {@code subId}, if the default network type is
6134 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6135 */
6136 private int getDefaultNetworkType(int subId) {
6137 return Integer.parseInt(
6138 TelephonyManager.getTelephonyProperty(
6139 mSubscriptionController.getPhoneId(subId),
6140 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6141 String.valueOf(Phone.PREFERRED_NT_MODE)));
6142 }
fionaxua13278b2018-03-21 00:08:13 -07006143
6144 @Override
6145 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6146 gid1, String gid2, String plmn, String spn) {
6147 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006148
6149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 final Phone phone = getPhone(subId);
6152 if (phone == null) {
6153 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6154 return;
6155 }
6156 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006159 }
fionaxua13278b2018-03-21 00:08:13 -07006160 }
6161
6162 @Override
6163 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006164 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006165
6166 final long identity = Binder.clearCallingIdentity();
6167 try {
6168 final Phone phone = getPhone(subId);
6169 if (phone == null) {
6170 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6171 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6172 }
6173 return phone.getCarrierIdListVersion();
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006176 }
fionaxua13278b2018-03-21 00:08:13 -07006177 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006178
6179 @Override
6180 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6182 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6183 return -1;
6184 }
6185
6186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006193
6194 @Override
6195 public int getCdmaRoamingMode(int subId) {
6196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6197 mApp, subId, "getCdmaRoamingMode");
6198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
6206
6207 @Override
6208 public boolean setCdmaRoamingMode(int subId, int mode) {
6209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6210 mApp, subId, "setCdmaRoamingMode");
6211
6212 final long identity = Binder.clearCallingIdentity();
6213 try {
6214 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6215 } finally {
6216 Binder.restoreCallingIdentity(identity);
6217 }
6218 }
6219
6220 @Override
6221 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6223 mApp, subId, "setCdmaSubscriptionMode");
6224
6225 final long identity = Binder.clearCallingIdentity();
6226 try {
6227 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
chen xu7ee67862018-10-30 22:27:10 -07006232
sqian2fff4a32018-11-05 14:18:37 -08006233 private void ensureUserRunning(int userId) {
6234 if (!mUserManager.isUserRunning(userId)) {
6235 throw new IllegalStateException("User " + userId + " does not exist or not running");
6236 }
6237 }
6238
6239 /**
6240 * Returns a list of SMS apps on a given user.
6241 *
6242 * Only the shell user (UID 2000 or 0) can call it.
6243 * Target user must be running.
6244 */
6245 @Override
6246 public String[] getSmsApps(int userId) {
6247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6248 ensureUserRunning(userId);
6249
6250 final Collection<SmsApplicationData> apps =
6251 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6252
6253 String[] ret = new String[apps.size()];
6254 int i = 0;
6255 for (SmsApplicationData app : apps) {
6256 ret[i++] = app.mPackageName;
6257 }
6258 return ret;
6259 }
6260
6261 /**
6262 * Returns the default SMS app package name on a given user.
6263 *
6264 * Only the shell user (UID 2000 or 0) can call it.
6265 * Target user must be running.
6266 */
6267 @Override
6268 public String getDefaultSmsApp(int userId) {
6269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6270 ensureUserRunning(userId);
6271
6272 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6273 /* updateIfNeeded= */ true, userId);
6274 return cn == null ? null : cn.getPackageName();
6275 }
6276
6277 /**
6278 * Set a package as the default SMS app on a given user.
6279 *
6280 * Only the shell user (UID 2000 or 0) can call it.
6281 * Target user must be running.
6282 */
6283 @Override
6284 public void setDefaultSmsApp(int userId, String packageName) {
6285 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6286 ensureUserRunning(userId);
6287
6288 boolean found = false;
6289 for (String pkg : getSmsApps(userId)) {
6290 if (TextUtils.equals(packageName, pkg)) {
6291 found = true;
6292 break;
6293 }
6294 }
6295 if (!found) {
6296 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6297 }
6298
6299 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6300 }
6301
chen xu7ee67862018-10-30 22:27:10 -07006302 @Override
sqian04b86072018-11-07 14:02:21 -08006303 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6304 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6306 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6307 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6308 }
6309 final long identity = Binder.clearCallingIdentity();
6310 try {
sqian991b35e2018-12-12 16:48:18 -08006311 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6312 for (Phone phone: PhoneFactory.getPhones()) {
6313 if (phone.getEmergencyNumberTracker() != null
6314 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6315 emergencyNumberListInternal.put(
6316 phone.getSubId(),
6317 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6318 }
sqian03bca152018-12-05 18:48:28 -08006319 }
sqian991b35e2018-12-12 16:48:18 -08006320 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
sqian04b86072018-11-07 14:02:21 -08006324 }
6325
6326 @Override
sqian03bca152018-12-05 18:48:28 -08006327 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6328 final Phone defaultPhone = getDefaultPhone();
6329 if (!exactMatch) {
6330 TelephonyPermissions
6331 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6332 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6333 }
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
sqian991b35e2018-12-12 16:48:18 -08006336 for (Phone phone: PhoneFactory.getPhones()) {
6337 if (phone.getEmergencyNumberTracker() != null
6338 && phone.getEmergencyNumberTracker() != null) {
6339 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6340 number, exactMatch)) {
6341 return true;
sqian03bca152018-12-05 18:48:28 -08006342 }
6343 }
sqian03bca152018-12-05 18:48:28 -08006344 }
6345 return false;
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
6349 }
6350
sqian04b86072018-11-07 14:02:21 -08006351 @Override
chen xu7ee67862018-10-30 22:27:10 -07006352 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6353 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6354 Phone phone = getPhone(subId);
6355 if (phone == null) {
6356 return null;
6357 }
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 UiccProfile profile = UiccController.getInstance()
6361 .getUiccProfileForPhone(phone.getPhoneId());
6362 if (profile != null) {
6363 return profile.getCertsFromCarrierPrivilegeAccessRules();
6364 }
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
6368 return null;
6369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006370}