blob: 3bad1551c3fd7c5240fc4c68f5594692b557da52 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Brad Ebinger34c09a52021-02-17 23:23:21 +000024import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080026import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070027import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080030import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070031import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070032import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.content.Context;
34import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070035import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070036import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080037import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070038import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080056import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080069import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080070import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070071import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070072import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080073import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070074import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080075import android.telephony.CellIdentityCdma;
76import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070078import android.telephony.CellInfoGsm;
79import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070080import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080081import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070082import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070083import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070084import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080085import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070086import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070088import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080089import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080090import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070091import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080094import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080095import android.telephony.SignalStrengthUpdateRequest;
96import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080097import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080099import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700101import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800103import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800104import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000105import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700106import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800108import android.telephony.data.ApnSetting;
109import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700110import android.telephony.gba.GbaAuthRequest;
111import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700112import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000114import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700115import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700116import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800117import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700118import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000121import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700122import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800124import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800126import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700129import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800131import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800132
Andrew Lee312e8172014-10-23 17:01:36 -0700133import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800134import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800135import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800136import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700138import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700139import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800140import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800143import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700145import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800146import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800147import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700148import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800150import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800152import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700153import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700154import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700157import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800158import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700159import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700160import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700161import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700162import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700163import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700164import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800166import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800167import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700169import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700171import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800172import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700173import com.android.internal.telephony.imsphone.ImsPhone;
174import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800175import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700176import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800178import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700181import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800186import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700187import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700188import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800190import com.android.phone.callcomposer.CallComposerPictureManager;
191import com.android.phone.callcomposer.CallComposerPictureTransfer;
192import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700193import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700194import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800195import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700196import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700197import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800198import com.android.services.telephony.TelecomAccountRegistry;
199import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800200import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800201
Hall Liu82694d52020-12-11 18:22:04 -0800202import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700203import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800204import java.io.IOException;
205import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700206import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800209import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800211import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100212import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800213import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700214import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800215import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800216import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800217import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800218import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800219import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220
221/**
222 * Implementation of the ITelephony interface.
223 */
Santos Cordon117fee72014-05-16 17:56:12 -0700224public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 private static final String LOG_TAG = "PhoneInterfaceManager";
226 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
227 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230 // Message codes used with mMainThreadHandler
231 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700232 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
233 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700234 private static final int CMD_OPEN_CHANNEL = 9;
235 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
236 private static final int CMD_CLOSE_CHANNEL = 11;
237 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800238 private static final int CMD_NV_READ_ITEM = 13;
239 private static final int EVENT_NV_READ_ITEM_DONE = 14;
240 private static final int CMD_NV_WRITE_ITEM = 15;
241 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
242 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
243 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700244 private static final int CMD_RESET_MODEM_CONFIG = 19;
245 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800246 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
247 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800248 private static final int CMD_SEND_ENVELOPE = 25;
249 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000250 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
251 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700252 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
253 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
254 private static final int CMD_EXCHANGE_SIM_IO = 31;
255 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800256 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
257 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700258 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
259 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700260 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
261 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700262 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
263 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
264 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
265 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700266 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
267 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
268 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
269 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700270 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800271 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
272 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000273 private static final int CMD_SWITCH_SLOTS = 50;
274 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700275 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
276 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
277 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
278 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
279 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
280 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
281 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
282 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700283 private static final int CMD_GET_ALL_CELL_INFO = 60;
284 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
285 private static final int CMD_GET_CELL_LOCATION = 62;
286 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700287 private static final int CMD_MODEM_REBOOT = 64;
288 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700289 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
290 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800291 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
292 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700293 private static final int CMD_GET_MODEM_STATUS = 70;
294 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700295 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
296 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700297 private static final int CMD_ERASE_MODEM_CONFIG = 74;
298 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800299 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
300 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
301 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
302 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800303 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
304 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800305 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800306 private static final int CMD_GET_CALL_FORWARDING = 83;
307 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
308 private static final int CMD_SET_CALL_FORWARDING = 85;
309 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
310 private static final int CMD_GET_CALL_WAITING = 87;
311 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
312 private static final int CMD_SET_CALL_WAITING = 89;
313 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700314 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
315 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
316 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
317 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700318 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
319 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800320 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
321 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800322 private static final int CMD_SET_DATA_THROTTLING = 99;
323 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800324 private static final int CMD_SET_SIM_POWER = 101;
325 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800326 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
327 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
328 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
329 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800330 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
331 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000332 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800334 // Parameters of select command.
335 private static final int SELECT_COMMAND = 0xA4;
336 private static final int SELECT_P1 = 0x04;
337 private static final int SELECT_P2 = 0;
338 private static final int SELECT_P3 = 0x10;
339
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 /** The singleton instance. */
341 private static PhoneInterfaceManager sInstance;
342
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800344 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800345 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700346 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private AppOpsManager mAppOps;
348 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800349 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800350 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700351 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 /** User Activity */
354 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800355 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
356
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700357 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
358
Derek Tan97ebb422014-09-05 16:55:38 -0700359 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
360 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800361 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800362 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700363
Michelecea4cf22018-12-21 15:00:11 -0800364 // String to store multi SIM allowed
365 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
366
Derek Tan740e1672017-06-27 14:56:27 -0700367 // The AID of ISD-R.
368 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
369
yinxub1bed742017-04-17 11:45:04 -0700370 private NetworkScanRequestTracker mNetworkScanRequestTracker;
371
David Kelly5e06a7f2018-03-12 14:10:59 +0000372 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
373 private static final int MANUFACTURER_CODE_LENGTH = 8;
374
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800375 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
376
Derek Tan89e89d42014-07-08 17:00:10 -0700377 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700378 * Experiment flag to enable erase modem config on reset network, default value is false
379 */
380 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
381 "reset_network_erase_modem_config_enabled";
382
Rambo Wang0f050d82021-02-12 11:43:36 -0800383 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
384
Naina Nallurid63128d2019-09-17 14:10:30 -0700385 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700386 * A request object to use for transmitting data to an ICC.
387 */
388 private static final class IccAPDUArgument {
389 public int channel, cla, command, p1, p2, p3;
390 public String data;
391
392 public IccAPDUArgument(int channel, int cla, int command,
393 int p1, int p2, int p3, String data) {
394 this.channel = channel;
395 this.cla = cla;
396 this.command = command;
397 this.p1 = p1;
398 this.p2 = p2;
399 this.p3 = p3;
400 this.data = data;
401 }
402 }
403
404 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700405 * A request object to use for transmitting data to an ICC.
406 */
407 private static final class ManualNetworkSelectionArgument {
408 public OperatorInfo operatorInfo;
409 public boolean persistSelection;
410
411 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
412 this.operatorInfo = operatorInfo;
413 this.persistSelection = persistSelection;
414 }
415 }
416
417 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
419 * request after sending. The main thread will notify the request when it is complete.
420 */
421 private static final class MainThreadRequest {
422 /** The argument to use for the request */
423 public Object argument;
424 /** The result of the request that is run on the main thread */
425 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800426 // The subscriber id that this request applies to. Defaults to
427 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
428 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429
Nathan Harold92bed182018-10-12 18:16:49 -0700430 // In cases where subId is unavailable, the caller needs to specify the phone.
431 public Phone phone;
432
vagdeviaf9a5b92018-08-15 16:01:53 -0700433 public WorkSource workSource;
434
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 public MainThreadRequest(Object argument) {
436 this.argument = argument;
437 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800438
Nathan Harold92bed182018-10-12 18:16:49 -0700439 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
440 this.argument = argument;
441 if (phone != null) {
442 this.phone = phone;
443 }
444 this.workSource = workSource;
445 }
446
vagdeviaf9a5b92018-08-15 16:01:53 -0700447 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800448 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800449 if (subId != null) {
450 this.subId = subId;
451 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 }
455
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800456 private static final class IncomingThirdPartyCallArgs {
457 public final ComponentName component;
458 public final String callId;
459 public final String callerDisplayName;
460
461 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
462 String callerDisplayName) {
463 this.component = component;
464 this.callId = callId;
465 this.callerDisplayName = callerDisplayName;
466 }
467 }
468
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 /**
470 * A handler that processes messages on the main thread in the phone process. Since many
471 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
472 * inbound binder threads to the main thread in the phone process. The Binder thread
473 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
474 * on, which will be notified when the operation completes and will contain the result of the
475 * request.
476 *
477 * <p>If a MainThreadRequest object is provided in the msg.obj field,
478 * note that request.result must be set to something non-null for the calling thread to
479 * unblock.
480 */
481 private final class MainThreadHandler extends Handler {
482 @Override
483 public void handleMessage(Message msg) {
484 MainThreadRequest request;
485 Message onCompleted;
486 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800487 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800489 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490
491 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 case CMD_HANDLE_USSD_REQUEST: {
493 request = (MainThreadRequest) msg.obj;
494 final Phone phone = getPhoneFromRequest(request);
495 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
496 String ussdRequest = ussdObject.first;
497 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700498
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 if (!isUssdApiAllowed(request.subId)) {
500 // Carrier does not support use of this API, return failure.
501 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
502 UssdResponse response = new UssdResponse(ussdRequest, null);
503 Bundle returnData = new Bundle();
504 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
505 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700506
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 request.result = true;
508 notifyRequester(request);
509 return;
510 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700511
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 try {
513 request.result = phone != null
514 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
515 } catch (CallStateException cse) {
516 request.result = false;
517 }
518 // Wake up the requesting thread
519 notifyRequester(request);
520 break;
pkanwar32d516d2016-10-14 19:37:38 -0700521 }
522
Yorke Lee716f67e2015-06-17 15:39:16 -0700523 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700525 final Phone phone = getPhoneFromRequest(request);
526 request.result = phone != null ?
527 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
528 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("iccTransmitApduLogicalChannel: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
544 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 iccArgument.channel, iccArgument.cla, iccArgument.command,
547 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 break;
551
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
559 if (ar.result == null) {
560 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800561 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800563 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 } else {
565 loge("iccTransmitApduLogicalChannel: Unknown exception");
566 }
567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
572 request = (MainThreadRequest) msg.obj;
573 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800574 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 if (uiccCard == null) {
576 loge("iccTransmitApduBasicChannel: No UICC");
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 } else {
580 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
581 request);
582 uiccCard.iccTransmitApduBasicChannel(
583 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
584 iccArgument.p3, iccArgument.data, onCompleted);
585 }
586 break;
587
588 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
589 ar = (AsyncResult) msg.obj;
590 request = (MainThreadRequest) ar.userObj;
591 if (ar.exception == null && ar.result != null) {
592 request.result = ar.result;
593 } else {
594 request.result = new IccIoResult(0x6F, 0, (byte[])null);
595 if (ar.result == null) {
596 loge("iccTransmitApduBasicChannel: Empty response");
597 } else if (ar.exception instanceof CommandException) {
598 loge("iccTransmitApduBasicChannel: CommandException: " +
599 ar.exception);
600 } else {
601 loge("iccTransmitApduBasicChannel: Unknown exception");
602 }
603 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 break;
606
607 case CMD_EXCHANGE_SIM_IO:
608 request = (MainThreadRequest) msg.obj;
609 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 if (uiccCard == null) {
612 loge("iccExchangeSimIO: No UICC");
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 } else {
616 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
617 request);
618 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
619 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
620 iccArgument.data, onCompleted);
621 }
622 break;
623
624 case EVENT_EXCHANGE_SIM_IO_DONE:
625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
627 if (ar.exception == null && ar.result != null) {
628 request.result = ar.result;
629 } else {
630 request.result = new IccIoResult(0x6f, 0, (byte[])null);
631 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 break;
634
Derek Tan4d5e5c12014-02-04 11:54:58 -0800635 case CMD_SEND_ENVELOPE:
636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800637 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 if (uiccCard == null) {
639 loge("sendEnvelopeWithStatus: No UICC");
640 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 } else {
643 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
644 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
645 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 break;
647
648 case EVENT_SEND_ENVELOPE_DONE:
649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800653 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700654 request.result = new IccIoResult(0x6F, 0, (byte[])null);
655 if (ar.result == null) {
656 loge("sendEnvelopeWithStatus: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("sendEnvelopeWithStatus: CommandException: " +
659 ar.exception);
660 } else {
661 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
662 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800663 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 break;
666
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 case CMD_OPEN_CHANNEL:
668 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800669 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800670 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 if (uiccCard == null) {
672 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800673 request.result = new IccOpenLogicalChannelResponse(-1,
674 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 } else {
677 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800678 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
679 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 break;
682
683 case EVENT_OPEN_CHANNEL_DONE:
684 ar = (AsyncResult) msg.obj;
685 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 int[] result = (int[]) ar.result;
689 int channelId = result[0];
690 byte[] selectResponse = null;
691 if (result.length > 1) {
692 selectResponse = new byte[result.length - 1];
693 for (int i = 1; i < result.length; ++i) {
694 selectResponse[i - 1] = (byte) result[i];
695 }
696 }
697 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700698 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 if (ar.result == null) {
701 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 if (ar.exception != null) {
704 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
705 }
706
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700708 if (ar.exception instanceof CommandException) {
709 CommandException.Error error =
710 ((CommandException) (ar.exception)).getCommandError();
711 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700713 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700714 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 }
716 }
717 openChannelResp = new IccOpenLogicalChannelResponse(
718 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700720 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 break;
723
724 case CMD_CLOSE_CHANNEL:
725 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800726 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 if (uiccCard == null) {
728 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900729 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 } else {
732 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
733 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800738 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
739 break;
740
741 case CMD_NV_READ_ITEM:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
745 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
748 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 ar = (AsyncResult) msg.obj;
750 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800751 if (ar.exception == null && ar.result != null) {
752 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800754 request.result = "";
755 if (ar.result == null) {
756 loge("nvReadItem: Empty response");
757 } else if (ar.exception instanceof CommandException) {
758 loge("nvReadItem: CommandException: " +
759 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800761 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 }
763 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 break;
766
Jake Hambye994d462014-02-03 13:10:13 -0800767 case CMD_NV_WRITE_ITEM:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
770 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800771 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700772 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800773 break;
774
775 case EVENT_NV_WRITE_ITEM_DONE:
776 handleNullReturnEvent(msg, "nvWriteItem");
777 break;
778
779 case CMD_NV_WRITE_CDMA_PRL:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800783 break;
784
785 case EVENT_NV_WRITE_CDMA_PRL_DONE:
786 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
787 break;
788
chen xu6dac5ab2018-10-26 17:39:23 -0700789 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800790 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700791 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
chen xu6dac5ab2018-10-26 17:39:23 -0700795 case EVENT_RESET_MODEM_CONFIG_DONE:
796 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800797 break;
798
Sooraj Sasindran37444802020-08-11 10:40:43 -0700799 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
802 request);
803 Phone phone = getPhoneFromRequest(request);
804 if (phone != null) {
805 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
806 } else {
807 loge("isNRDualConnectivityEnabled: No phone object");
808 request.result = false;
809 notifyRequester(request);
810 }
811 break;
812 }
813
814 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null && ar.result != null) {
818 request.result = ar.result;
819 } else {
820 // request.result must be set to something non-null
821 // for the calling thread to unblock
822 if (request.result != null) {
823 request.result = ar.result;
824 } else {
825 request.result = false;
826 }
827 if (ar.result == null) {
828 loge("isNRDualConnectivityEnabled: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("isNRDualConnectivityEnabled: CommandException: "
831 + ar.exception);
832 } else {
833 loge("isNRDualConnectivityEnabled: Unknown exception");
834 }
835 }
836 notifyRequester(request);
837 break;
838
839 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
842 Phone phone = getPhoneFromRequest(request);
843 if (phone != null) {
844 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
845 request.workSource);
846 } else {
847 loge("enableNrDualConnectivity: No phone object");
848 request.result =
849 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
850 notifyRequester(request);
851 }
852 break;
853 }
854
855 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null) {
859 request.result =
860 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
861 } else {
862 request.result =
863 TelephonyManager
864 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
865 if (ar.exception instanceof CommandException) {
866 CommandException.Error error =
867 ((CommandException) (ar.exception)).getCommandError();
868 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
869 request.result =
870 TelephonyManager
871 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
872 }
873 loge("enableNrDualConnectivity" + ": CommandException: "
874 + ar.exception);
875 } else {
876 loge("enableNrDualConnectivity" + ": Unknown exception");
877 }
878 }
879 notifyRequester(request);
880 break;
881 }
882
SongFerngWang3ef3e072020-12-21 16:41:52 +0800883 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800884 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800885 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
886 request);
887 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 break;
889
SongFerngWang3ef3e072020-12-21 16:41:52 +0800890 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result; // Integer
895 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530896 // request.result must be set to something non-null
897 // for the calling thread to unblock
898 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 loge("getAllowedNetworkTypesBitmask: CommandException: "
903 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800905 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 }
907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 break;
910
SongFerngWang3ef3e072020-12-21 16:41:52 +0800911 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800913 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
914 request);
915 Pair<Integer, Long> reasonWithNetworkTypes =
916 (Pair<Integer, Long>) request.argument;
917 getPhoneFromRequest(request).setAllowedNetworkTypes(
918 reasonWithNetworkTypes.first,
919 reasonWithNetworkTypes.second,
920 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 break;
922
SongFerngWang3ef3e072020-12-21 16:41:52 +0800923 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
924 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 break;
926
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000927 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
928 request = (MainThreadRequest)msg.obj;
929 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800930 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000931 break;
932
933 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
934 ar = (AsyncResult)msg.obj;
935 request = (MainThreadRequest)ar.userObj;
936 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700937 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000938 break;
939
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800940 case CMD_SET_VOICEMAIL_NUMBER:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
943 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800944 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
945 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800946 break;
947
948 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
949 handleNullReturnEvent(msg, "setVoicemailNumber");
950 break;
951
Stuart Scott54788802015-03-30 13:18:01 -0700952 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
955 request);
956 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
957 break;
958
959 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
960 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
961 break;
962
Shishir Agrawal302c8692015-06-19 13:49:39 -0700963 case CMD_PERFORM_NETWORK_SCAN:
964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
966 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
967 break;
968
Hall Liu27d24262020-09-18 19:04:59 -0700969 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700972 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
973 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
974 request.argument;
975 int callForwardingReason = args.first;
976 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800977 break;
Hall Liu27d24262020-09-18 19:04:59 -0700978 }
979 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700982 TelephonyManager.CallForwardingInfoCallback callback =
983 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
984 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800985 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700986 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800987 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
988 for (CallForwardInfo callForwardInfo : callForwardInfos) {
989 // Service Class is a bit mask per 3gpp 27.007. Search for
990 // any service for voice call.
991 if ((callForwardInfo.serviceClass
992 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700993 callForwardingInfo = new CallForwardingInfo(true,
994 callForwardInfo.reason,
995 callForwardInfo.number,
996 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800997 break;
998 }
999 }
1000 // Didn't find a call forward info for voice call.
1001 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001002 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1003 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001004 }
Hall Liu27d24262020-09-18 19:04:59 -07001005 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001006 } else {
1007 if (ar.result == null) {
1008 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1009 }
1010 if (ar.exception != null) {
1011 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1012 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001013 int errorCode = TelephonyManager
1014 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001015 if (ar.exception instanceof CommandException) {
1016 CommandException.Error error =
1017 ((CommandException) (ar.exception)).getCommandError();
1018 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001019 errorCode = TelephonyManager
1020 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001021 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001022 errorCode = TelephonyManager
1023 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001024 }
1025 }
Hall Liu27d24262020-09-18 19:04:59 -07001026 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001027 }
Shuo Qian4a594052020-01-23 11:59:30 -08001028 break;
Hall Liu27d24262020-09-18 19:04:59 -07001029 }
Shuo Qian4a594052020-01-23 11:59:30 -08001030
Hall Liu27d24262020-09-18 19:04:59 -07001031 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001032 request = (MainThreadRequest) msg.obj;
1033 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001034 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001035 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001036 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1037 request.argument).first;
1038 request.phone.setCallForwardingOption(
1039 callForwardingInfoToSet.isEnabled()
1040 ? CommandsInterface.CF_ACTION_ENABLE
1041 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001042 callForwardingInfoToSet.getReason(),
1043 callForwardingInfoToSet.getNumber(),
1044 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1045 break;
Hall Liu27d24262020-09-18 19:04:59 -07001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047
Hall Liu27d24262020-09-18 19:04:59 -07001048 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001049 ar = (AsyncResult) msg.obj;
1050 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001051 Consumer<Integer> callback =
1052 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1053 request.argument).second;
1054 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001055 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001056 int errorCode = TelephonyManager.CallForwardingInfoCallback
1057 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001058 if (ar.exception instanceof CommandException) {
1059 CommandException.Error error =
1060 ((CommandException) (ar.exception)).getCommandError();
1061 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001062 errorCode = TelephonyManager.CallForwardingInfoCallback
1063 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001064 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001065 errorCode = TelephonyManager.CallForwardingInfoCallback
1066 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001067 }
1068 }
1069 callback.accept(errorCode);
1070 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001071 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001072 }
Shuo Qian4a594052020-01-23 11:59:30 -08001073 break;
Hall Liu27d24262020-09-18 19:04:59 -07001074 }
Shuo Qian4a594052020-01-23 11:59:30 -08001075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1079 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1080 break;
Hall Liu27d24262020-09-18 19:04:59 -07001081 }
Shuo Qian4a594052020-01-23 11:59:30 -08001082
Hall Liu27d24262020-09-18 19:04:59 -07001083 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001086 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001087 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1088 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001089 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001090 // Service Class is a bit mask per 3gpp 27.007.
1091 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001092 if (callForwardResults.length > 1
1093 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001094 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001095 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001096 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1097 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001098 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001099 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001100 }
1101 } else {
1102 if (ar.result == null) {
1103 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1104 }
1105 if (ar.exception != null) {
1106 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1107 }
1108 if (ar.exception instanceof CommandException) {
1109 CommandException.Error error =
1110 ((CommandException) (ar.exception)).getCommandError();
1111 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1112 callForwardingStatus =
1113 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1114 }
1115 }
1116 }
Hall Liu27d24262020-09-18 19:04:59 -07001117 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001118 break;
Hall Liu27d24262020-09-18 19:04:59 -07001119 }
Shuo Qian4a594052020-01-23 11:59:30 -08001120
Hall Liu27d24262020-09-18 19:04:59 -07001121 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001124 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1125 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001126 break;
Hall Liu27d24262020-09-18 19:04:59 -07001127 }
Shuo Qian4a594052020-01-23 11:59:30 -08001128
Hall Liu27d24262020-09-18 19:04:59 -07001129 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001130 ar = (AsyncResult) msg.obj;
1131 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001132 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1133 Consumer<Integer> callback =
1134 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1135 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001136 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001137 if (ar.exception instanceof CommandException) {
1138 CommandException.Error error =
1139 ((CommandException) (ar.exception)).getCommandError();
1140 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1141 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1142 } else {
1143 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1144 }
1145 } else {
1146 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1147 }
1148 } else {
1149 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1150 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001151 }
Shuo Qian4a594052020-01-23 11:59:30 -08001152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
Shuo Qian4a594052020-01-23 11:59:30 -08001154
Shishir Agrawal302c8692015-06-19 13:49:39 -07001155 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
1158 CellNetworkScanResult cellScanResult;
1159 if (ar.exception == null && ar.result != null) {
1160 cellScanResult = new CellNetworkScanResult(
1161 CellNetworkScanResult.STATUS_SUCCESS,
1162 (List<OperatorInfo>) ar.result);
1163 } else {
1164 if (ar.result == null) {
1165 loge("getCellNetworkScanResults: Empty response");
1166 }
1167 if (ar.exception != null) {
1168 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1169 }
1170 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1171 if (ar.exception instanceof CommandException) {
1172 CommandException.Error error =
1173 ((CommandException) (ar.exception)).getCommandError();
1174 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1175 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1176 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1177 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1178 }
1179 }
1180 cellScanResult = new CellNetworkScanResult(errorCode, null);
1181 }
1182 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001183 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001184 break;
1185
1186 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1187 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001188 ManualNetworkSelectionArgument selArg =
1189 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001190 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1191 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001192 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1193 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 break;
1195
1196 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
1199 if (ar.exception == null) {
1200 request.result = true;
1201 } else {
1202 request.result = false;
1203 loge("setNetworkSelectionModeManual " + ar.exception);
1204 }
1205 notifyRequester(request);
1206 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 break;
1208
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001209 case CMD_GET_MODEM_ACTIVITY_INFO:
1210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001212 if (defaultPhone != null) {
1213 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001214 } else {
1215 ResultReceiver result = (ResultReceiver) request.argument;
1216 Bundle bundle = new Bundle();
1217 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001218 new ModemActivityInfo(0, 0, 0,
1219 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001220 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001221 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 break;
1223
Hall Liud0f208c2020-10-14 16:54:44 -07001224 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001227 ResultReceiver result = (ResultReceiver) request.argument;
1228
Hall Liud0f208c2020-10-14 16:54:44 -07001229 ModemActivityInfo ret = null;
1230 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001231 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 // Update the last modem activity info and the result of the request.
1233 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1234 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001235 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001236 int[] txTimeMs = info.getTransmitTimeMillis();
1237 int[] lastModemTxTimeMs = mLastModemActivityInfo
1238 .getTransmitTimeMillis();
1239 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1240 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1241 }
Hall Liu49656c02020-10-09 19:00:11 -07001242 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001243 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1244 + mLastModemActivityInfo.getSleepTimeMillis());
1245 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1246 + mLastModemActivityInfo.getIdleTimeMillis());
1247 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1248 mLastModemActivityInfo.setReceiveTimeMillis(
1249 info.getReceiveTimeMillis()
1250 + mLastModemActivityInfo.getReceiveTimeMillis());
1251 }
Hall Liu49656c02020-10-09 19:00:11 -07001252 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001253 mLastModemActivityInfo.getSleepTimeMillis(),
1254 mLastModemActivityInfo.getIdleTimeMillis(),
1255 mLastModemActivityInfo.getTransmitTimeMillis(),
1256 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001257 } else {
1258 if (ar.result == null) {
1259 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001260 error = TelephonyManager.ModemActivityInfoException
1261 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001262 } else if (ar.exception instanceof CommandException) {
1263 loge("queryModemActivityInfo: CommandException: " +
1264 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001265 error = TelephonyManager.ModemActivityInfoException
1266 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 } else {
1268 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001269 error = TelephonyManager.ModemActivityInfoException
1270 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001271 }
1272 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001273 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001274 if (ret != null) {
1275 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1276 } else {
1277 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1278 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001279 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001280 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001281 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001282 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001283
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 case CMD_SET_ALLOWED_CARRIERS:
1285 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001286 CarrierRestrictionRules argument =
1287 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001288 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001289 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001290 break;
1291
1292 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1293 ar = (AsyncResult) msg.obj;
1294 request = (MainThreadRequest) ar.userObj;
1295 if (ar.exception == null && ar.result != null) {
1296 request.result = ar.result;
1297 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001298 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1299 if (ar.exception instanceof CommandException) {
1300 loge("setAllowedCarriers: CommandException: " + ar.exception);
1301 CommandException.Error error =
1302 ((CommandException) (ar.exception)).getCommandError();
1303 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1304 request.result =
1305 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1306 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 } else {
1308 loge("setAllowedCarriers: Unknown exception");
1309 }
1310 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001311 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001312 break;
1313
1314 case CMD_GET_ALLOWED_CARRIERS:
1315 request = (MainThreadRequest) msg.obj;
1316 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001317 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001318 break;
1319
1320 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
1323 if (ar.exception == null && ar.result != null) {
1324 request.result = ar.result;
1325 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001326 request.result = new IllegalStateException(
1327 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001328 if (ar.result == null) {
1329 loge("getAllowedCarriers: Empty response");
1330 } else if (ar.exception instanceof CommandException) {
1331 loge("getAllowedCarriers: CommandException: " +
1332 ar.exception);
1333 } else {
1334 loge("getAllowedCarriers: Unknown exception");
1335 }
1336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001338 break;
1339
Nathan Haroldb3014052017-01-25 15:57:32 -08001340 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 if (ar.exception == null && ar.result != null) {
1344 request.result = ar.result;
1345 } else {
1346 request.result = new IllegalArgumentException(
1347 "Failed to retrieve Forbidden Plmns");
1348 if (ar.result == null) {
1349 loge("getForbiddenPlmns: Empty response");
1350 } else {
1351 loge("getForbiddenPlmns: Unknown exception");
1352 }
1353 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001354 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001355 break;
1356
1357 case CMD_GET_FORBIDDEN_PLMNS:
1358 request = (MainThreadRequest) msg.obj;
1359 uiccCard = getUiccCardFromRequest(request);
1360 if (uiccCard == null) {
1361 loge("getForbiddenPlmns() UiccCard is null");
1362 request.result = new IllegalArgumentException(
1363 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001364 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001365 break;
1366 }
1367 Integer appType = (Integer) request.argument;
1368 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1369 if (uiccApp == null) {
1370 loge("getForbiddenPlmns() no app with specified type -- "
1371 + appType);
1372 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001374 break;
1375 } else {
1376 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1377 + " specified type -- " + appType);
1378 }
1379 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1380 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1381 onCompleted);
1382 break;
1383
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001384 case CMD_SWITCH_SLOTS:
1385 request = (MainThreadRequest) msg.obj;
1386 int[] physicalSlots = (int[]) request.argument;
1387 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1388 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1389 break;
1390
1391 case EVENT_SWITCH_SLOTS_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001395 notifyRequester(request);
1396 break;
1397 case CMD_GET_NETWORK_SELECTION_MODE:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1400 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1401 break;
1402
1403 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
1406 if (ar.exception != null) {
1407 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1408 } else {
1409 int mode = ((int[]) ar.result)[0];
1410 if (mode == 0) {
1411 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1412 } else {
1413 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1414 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 notifyRequester(request);
1417 break;
1418 case CMD_GET_CDMA_ROAMING_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1421 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1422 break;
1423 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception != null) {
1427 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1428 } else {
1429 request.result = ((int[]) ar.result)[0];
1430 }
1431 notifyRequester(request);
1432 break;
1433 case CMD_SET_CDMA_ROAMING_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1436 int mode = (int) request.argument;
1437 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1438 break;
1439 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
1442 request.result = ar.exception == null;
1443 notifyRequester(request);
1444 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001445 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1448 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1449 break;
1450 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
1453 if (ar.exception != null) {
1454 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1455 } else {
1456 request.result = ((int[]) ar.result)[0];
1457 }
1458 notifyRequester(request);
1459 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1463 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001464 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1465 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001466 break;
1467 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 request.result = ar.exception == null;
1471 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001472 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001473 case CMD_GET_ALL_CELL_INFO:
1474 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001475 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001476 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 case EVENT_GET_ALL_CELL_INFO_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001481 // If a timeout occurs, the response will be null
1482 request.result = (ar.exception == null && ar.result != null)
1483 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 synchronized (request) {
1485 request.notifyAll();
1486 }
1487 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001488 case CMD_REQUEST_CELL_INFO_UPDATE:
1489 request = (MainThreadRequest) msg.obj;
1490 request.phone.requestCellInfoUpdate(request.workSource,
1491 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1492 break;
1493 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1494 ar = (AsyncResult) msg.obj;
1495 request = (MainThreadRequest) ar.userObj;
1496 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1497 try {
1498 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001499 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001500 cb.onError(
1501 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1502 ar.exception.getClass().getName(),
1503 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001504 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001505 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001506 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001507 } else {
1508 // use the result as returned
1509 cb.onCellInfo((List<CellInfo>) ar.result);
1510 }
1511 } catch (RemoteException re) {
1512 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1513 }
1514 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001515 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001516 request = (MainThreadRequest) msg.obj;
1517 WorkSource ws = (WorkSource) request.argument;
1518 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001519 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001520 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001521 }
1522 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001523 ar = (AsyncResult) msg.obj;
1524 request = (MainThreadRequest) ar.userObj;
1525 if (ar.exception == null) {
1526 request.result = ar.result;
1527 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001528 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001529 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001530 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001531 }
1532
1533 synchronized (request) {
1534 request.notifyAll();
1535 }
1536 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001537 }
chen xu6dac5ab2018-10-26 17:39:23 -07001538 case CMD_MODEM_REBOOT:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001541 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001542 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001543 case EVENT_CMD_MODEM_REBOOT_DONE:
1544 handleNullReturnEvent(msg, "rebootModem");
1545 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001546 case CMD_REQUEST_ENABLE_MODEM:
1547 request = (MainThreadRequest) msg.obj;
1548 boolean enable = (boolean) request.argument;
1549 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001550 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001551 PhoneConfigurationManager.getInstance()
1552 .enablePhone(request.phone, enable, onCompleted);
1553 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001554 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001558 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001559 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001560 if ((boolean) request.result) {
1561 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1562 updateModemStateMetrics();
1563 } else {
1564 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1565 + ar.exception);
1566 }
1567 notifyRequester(request);
1568 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001569 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001570 case CMD_GET_MODEM_STATUS:
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1573 PhoneConfigurationManager.getInstance()
1574 .getPhoneStatusFromModem(request.phone, onCompleted);
1575 break;
1576 case EVENT_GET_MODEM_STATUS_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 int id = request.phone.getPhoneId();
1580 if (ar.exception == null && ar.result != null) {
1581 request.result = ar.result;
1582 //update the cache as modem status has changed
1583 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1584 (boolean) request.result);
1585 } else {
1586 // Return true if modem status cannot be retrieved. For most cases,
1587 // modem status is on. And for older version modems, GET_MODEM_STATUS
1588 // and disable modem are not supported. Modem is always on.
1589 // TODO: this should be fixed in R to support a third
1590 // status UNKNOWN b/131631629
1591 request.result = true;
1592 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1593 + ar.exception);
1594 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001595 notifyRequester(request);
1596 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001597 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1598 request = (MainThreadRequest) msg.obj;
1599 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1600 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1601 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1602 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1603 break;
1604 }
1605 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
1608 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1609 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1610 args.second.accept(ar.exception == null);
1611 notifyRequester(request);
1612 break;
1613 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001614 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1615 request = (MainThreadRequest) msg.obj;
1616 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1617 Phone phone = getPhoneFromRequest(request);
1618 if (phone != null) {
1619 phone.getSystemSelectionChannels(onCompleted);
1620 } else {
1621 loge("getSystemSelectionChannels: No phone object");
1622 request.result = new ArrayList<RadioAccessSpecifier>();
1623 notifyRequester(request);
1624 }
1625 break;
1626 }
1627 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null && ar.result != null) {
1631 request.result = ar.result;
1632 } else {
1633 request.result = new IllegalArgumentException(
1634 "Failed to retrieve system selection channels");
1635 if (ar.result == null) {
1636 loge("getSystemSelectionChannels: Empty response");
1637 } else {
1638 loge("getSystemSelectionChannels: Unknown exception");
1639 }
1640 }
1641 notifyRequester(request);
1642 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001643 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1644 ar = (AsyncResult) msg.obj;
1645 request = (MainThreadRequest) ar.userObj;
1646 if (ar.exception == null && ar.result != null) {
1647 request.result = ar.result;
1648 } else {
1649 request.result = -1;
1650 loge("Failed to set Forbidden Plmns");
1651 if (ar.result == null) {
1652 loge("setForbidenPlmns: Empty response");
1653 } else if (ar.exception != null) {
1654 loge("setForbiddenPlmns: Exception: " + ar.exception);
1655 request.result = -1;
1656 } else {
1657 loge("setForbiddenPlmns: Unknown exception");
1658 }
1659 }
1660 notifyRequester(request);
1661 break;
1662 case CMD_SET_FORBIDDEN_PLMNS:
1663 request = (MainThreadRequest) msg.obj;
1664 uiccCard = getUiccCardFromRequest(request);
1665 if (uiccCard == null) {
1666 loge("setForbiddenPlmns: UiccCard is null");
1667 request.result = -1;
1668 notifyRequester(request);
1669 break;
1670 }
1671 Pair<Integer, List<String>> setFplmnsArgs =
1672 (Pair<Integer, List<String>>) request.argument;
1673 appType = setFplmnsArgs.first;
1674 List<String> fplmns = setFplmnsArgs.second;
1675 uiccApp = uiccCard.getApplicationByType(appType);
1676 if (uiccApp == null) {
1677 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1678 request.result = -1;
1679 loge("Failed to get UICC App");
1680 notifyRequester(request);
1681 } else {
1682 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1683 ((SIMRecords) uiccApp.getIccRecords())
1684 .setForbiddenPlmns(onCompleted, fplmns);
1685 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001686 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001687 case CMD_ERASE_MODEM_CONFIG:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1690 defaultPhone.eraseModemConfig(onCompleted);
1691 break;
1692 case EVENT_ERASE_MODEM_CONFIG_DONE:
1693 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001694 break;
zoey chene02881a2019-12-30 16:11:23 +08001695
1696 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1699 Pair<String, String> changed = (Pair<String, String>) request.argument;
1700 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1701 changed.first, changed.second, onCompleted);
1702 break;
1703 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 if (ar.exception == null) {
1707 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001708 // If the operation is successful, update the PIN storage
1709 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1710 int phoneId = getPhoneFromRequest(request).getPhoneId();
1711 UiccController.getInstance().getPinStorage()
1712 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001713 } else {
1714 request.result = msg.arg1;
1715 }
1716 notifyRequester(request);
1717 break;
1718
Michele Berionne5e411512020-11-13 02:36:59 +00001719 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1722 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1723 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1724 enabled.first, enabled.second, onCompleted);
1725 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001726 }
zoey chene02881a2019-12-30 16:11:23 +08001727 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730 if (ar.exception == null) {
1731 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001732 // If the operation is successful, update the PIN storage
1733 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1734 int phoneId = getPhoneFromRequest(request).getPhoneId();
1735 if (enabled.first) {
1736 UiccController.getInstance().getPinStorage()
1737 .storePin(enabled.second, phoneId);
1738 } else {
1739 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1740 }
zoey chene02881a2019-12-30 16:11:23 +08001741 } else {
1742 request.result = msg.arg1;
1743 }
Michele Berionne5e411512020-11-13 02:36:59 +00001744
1745
zoey chene02881a2019-12-30 16:11:23 +08001746 notifyRequester(request);
1747 break;
1748
Peter Wangdafb9ac2020-01-15 14:13:38 -08001749 case MSG_NOTIFY_USER_ACTIVITY:
1750 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001751 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001752 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1753 getDefaultPhone().getContext().sendBroadcastAsUser(
1754 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1755 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001756
1757 case CMD_SET_DATA_THROTTLING: {
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1760 DataThrottlingRequest dataThrottlingRequest =
1761 (DataThrottlingRequest) request.argument;
1762 Phone phone = getPhoneFromRequest(request);
1763 if (phone != null) {
1764 phone.setDataThrottling(onCompleted,
1765 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1766 dataThrottlingRequest.getCompletionDurationMillis());
1767 } else {
1768 loge("setDataThrottling: No phone object");
1769 request.result =
1770 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1771 notifyRequester(request);
1772 }
1773
1774 break;
1775 }
1776 case EVENT_SET_DATA_THROTTLING_DONE:
1777 ar = (AsyncResult) msg.obj;
1778 request = (MainThreadRequest) ar.userObj;
1779
1780 if (ar.exception == null) {
1781 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1782 } else if (ar.exception instanceof CommandException) {
1783 loge("setDataThrottling: CommandException: " + ar.exception);
1784 CommandException.Error error =
1785 ((CommandException) (ar.exception)).getCommandError();
1786
1787 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1788 request.result = TelephonyManager
1789 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1790 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1791 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1792 } else {
1793 request.result =
1794 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1795 }
1796 } else {
1797 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1798 }
1799 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1800 notifyRequester(request);
1801 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001802
1803 case CMD_SET_SIM_POWER: {
1804 request = (MainThreadRequest) msg.obj;
1805 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1806 request = (MainThreadRequest) msg.obj;
1807 int stateToSet =
1808 ((Pair<Integer, IIntegerConsumer>)
1809 request.argument).first;
1810 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1811 break;
1812 }
1813 case EVENT_SET_SIM_POWER_DONE: {
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 IIntegerConsumer callback =
1817 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1818 if (ar.exception != null) {
1819 loge("setSimPower exception: " + ar.exception);
1820 int errorCode = TelephonyManager.CallForwardingInfoCallback
1821 .RESULT_ERROR_UNKNOWN;
1822 if (ar.exception instanceof CommandException) {
1823 CommandException.Error error =
1824 ((CommandException) (ar.exception)).getCommandError();
1825 if (error == CommandException.Error.SIM_ERR) {
1826 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1827 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1828 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1829 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1830 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1831 } else {
1832 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1833 }
1834 }
1835 try {
1836 callback.accept(errorCode);
1837 } catch (RemoteException e) {
1838 // Ignore if the remote process is no longer available to call back.
1839 Log.w(LOG_TAG, "setSimPower: callback not available.");
1840 }
1841 } else {
1842 try {
1843 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1844 } catch (RemoteException e) {
1845 // Ignore if the remote process is no longer available to call back.
1846 Log.w(LOG_TAG, "setSimPower: callback not available.");
1847 }
1848 }
1849 break;
1850 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001851 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1852 request = (MainThreadRequest) msg.obj;
1853
1854 final Phone phone = getPhoneFromRequest(request);
1855 if (phone == null || phone.getServiceStateTracker() == null) {
1856 request.result = new IllegalStateException("Phone or SST is null");
1857 notifyRequester(request);
1858 break;
1859 }
1860
1861 Pair<Integer, SignalStrengthUpdateRequest> pair =
1862 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1863 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1864 request);
1865 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1866 request.subId, pair.first /*callingUid*/,
1867 pair.second /*request*/, onCompleted);
1868 break;
1869 }
1870 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1871 ar = (AsyncResult) msg.obj;
1872 request = (MainThreadRequest) ar.userObj;
1873 // request.result will be the exception of ar if present, true otherwise.
1874 // Be cautious not to leave result null which will wait() forever
1875 request.result = ar.exception != null ? ar.exception : true;
1876 notifyRequester(request);
1877 break;
1878 }
1879 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1880 request = (MainThreadRequest) msg.obj;
1881
1882 Phone phone = getPhoneFromRequest(request);
1883 if (phone == null || phone.getServiceStateTracker() == null) {
1884 request.result = new IllegalStateException("Phone or SST is null");
1885 notifyRequester(request);
1886 break;
1887 }
1888
1889 Pair<Integer, SignalStrengthUpdateRequest> pair =
1890 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1891 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1892 request);
1893 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1894 request.subId, pair.first /*callingUid*/,
1895 pair.second /*request*/, onCompleted);
1896 break;
1897 }
1898 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 request.result = ar.exception != null ? ar.exception : true;
1902 notifyRequester(request);
1903 break;
1904 }
Jordan Liu109698e2020-11-24 14:50:34 -08001905
Michele Berionne5e411512020-11-13 02:36:59 +00001906 case CMD_PREPARE_UNATTENDED_REBOOT:
1907 request = (MainThreadRequest) msg.obj;
1908 request.result =
1909 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1910 notifyRequester(request);
1911 break;
1912
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 default:
1914 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1915 break;
1916 }
1917 }
Jake Hambye994d462014-02-03 13:10:13 -08001918
Pengquan Menga1bb6272018-09-06 09:59:22 -07001919 private void notifyRequester(MainThreadRequest request) {
1920 synchronized (request) {
1921 request.notifyAll();
1922 }
1923 }
1924
Jake Hambye994d462014-02-03 13:10:13 -08001925 private void handleNullReturnEvent(Message msg, String command) {
1926 AsyncResult ar = (AsyncResult) msg.obj;
1927 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1928 if (ar.exception == null) {
1929 request.result = true;
1930 } else {
1931 request.result = false;
1932 if (ar.exception instanceof CommandException) {
1933 loge(command + ": CommandException: " + ar.exception);
1934 } else {
1935 loge(command + ": Unknown exception");
1936 }
1937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001938 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
1942 /**
1943 * Posts the specified command to be executed on the main thread,
1944 * waits for the request to complete, and returns the result.
1945 * @see #sendRequestAsync
1946 */
1947 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001948 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1949 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001950 }
1951
1952 /**
1953 * Posts the specified command to be executed on the main thread,
1954 * waits for the request to complete, and returns the result.
1955 * @see #sendRequestAsync
1956 */
1957 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1958 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001959 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001960 }
1961
1962 /**
1963 * Posts the specified command to be executed on the main thread,
1964 * waits for the request to complete, and returns the result.
1965 * @see #sendRequestAsync
1966 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001967 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001968 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1969 }
1970
1971 /**
1972 * Posts the specified command to be executed on the main thread,
1973 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1974 * if not timeout or null otherwise.
1975 * @see #sendRequestAsync
1976 */
1977 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1978 long timeoutInMs) {
1979 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001980 }
1981
1982 /**
1983 * Posts the specified command to be executed on the main thread,
1984 * waits for the request to complete, and returns the result.
1985 * @see #sendRequestAsync
1986 */
Nathan Harold92bed182018-10-12 18:16:49 -07001987 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001988 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001989 }
1990
1991 /**
1992 * Posts the specified command to be executed on the main thread,
1993 * waits for the request to complete, and returns the result.
1994 * @see #sendRequestAsync
1995 */
1996 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001997 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1998 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001999 }
2000
2001 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002002 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2003 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2004 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002005 * @see #sendRequestAsync
2006 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002007 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2008 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2010 throw new RuntimeException("This method will deadlock if called from the main thread.");
2011 }
2012
Nathan Harold92bed182018-10-12 18:16:49 -07002013 MainThreadRequest request = null;
2014 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2015 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2016 } else if (phone != null) {
2017 request = new MainThreadRequest(argument, phone, workSource);
2018 } else {
2019 request = new MainThreadRequest(argument, subId, workSource);
2020 }
2021
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 Message msg = mMainThreadHandler.obtainMessage(command, request);
2023 msg.sendToTarget();
2024
Rambo Wang0f050d82021-02-12 11:43:36 -08002025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002027 if (timeoutInMs >= 0) {
2028 // Wait for at least timeoutInMs before returning null request result
2029 long now = SystemClock.elapsedRealtime();
2030 long deadline = now + timeoutInMs;
2031 while (request == null && now < deadline) {
2032 try {
2033 request.wait(deadline - now);
2034 } catch (InterruptedException e) {
2035 // Do nothing, go back and check if request is completed or timeout
2036 } finally {
2037 now = SystemClock.elapsedRealtime();
2038 }
2039 }
2040 } else {
2041 // Wait for the request to complete
2042 while (request.result == null) {
2043 try {
2044 request.wait();
2045 } catch (InterruptedException e) {
2046 // Do nothing, go back and wait until the request is complete
2047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 }
2049 }
2050 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002051 if (request.result == null) {
2052 Log.wtf(LOG_TAG,
2053 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 return request.result;
2056 }
2057
2058 /**
2059 * Asynchronous ("fire and forget") version of sendRequest():
2060 * Posts the specified command to be executed on the main thread, and
2061 * returns immediately.
2062 * @see #sendRequest
2063 */
2064 private void sendRequestAsync(int command) {
2065 mMainThreadHandler.sendEmptyMessage(command);
2066 }
2067
2068 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002069 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002071 */
2072 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002073 sendRequestAsync(command, argument, null, null);
2074 }
2075
2076 /**
2077 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2078 * @see {@link #sendRequest(int,Object)}
2079 */
2080 private void sendRequestAsync(
2081 int command, Object argument, Phone phone, WorkSource workSource) {
2082 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002083 Message msg = mMainThreadHandler.obtainMessage(command, request);
2084 msg.sendToTarget();
2085 }
2086
2087 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 * Initialize the singleton PhoneInterfaceManager instance.
2089 * This is only done once, at startup, from PhoneApp.onCreate().
2090 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002091 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 synchronized (PhoneInterfaceManager.class) {
2093 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002094 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 } else {
2096 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2097 }
2098 return sInstance;
2099 }
2100 }
2101
2102 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002103 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002106 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002107 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2109 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002110 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002111 mTelephonySharedPreferences =
2112 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002113 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002114 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002115 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002116
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 publish();
2118 }
2119
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002120 private Phone getDefaultPhone() {
2121 Phone thePhone = getPhone(getDefaultSubscription());
2122 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2123 }
2124
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 private void publish() {
2126 if (DBG) log("publish: " + this);
2127
Peter Wangc035ce42020-01-08 21:00:22 -08002128 TelephonyFrameworkInitializer
2129 .getTelephonyServiceManager()
2130 .getTelephonyServiceRegisterer()
2131 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
Stuart Scott584921c2015-01-15 17:10:34 -08002134 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002135 if (request.phone != null) {
2136 return request.phone;
2137 } else {
2138 return getPhoneFromSubId(request.subId);
2139 }
2140 }
2141
2142 private Phone getPhoneFromSubId(int subId) {
2143 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2144 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002145 }
2146
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002147 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2148 Phone phone = getPhoneFromRequest(request);
2149 return phone == null ? null :
2150 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2151 }
2152
Wink Saville36469e72014-06-11 15:17:00 -07002153 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002154 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002155 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157
Naina Nallurid63128d2019-09-17 14:10:30 -07002158 private void sendEraseModemConfig(Phone phone) {
2159 if (phone != null) {
2160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2161 mApp, phone.getSubId(), "eraseModemConfig");
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2165 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
2169 }
2170 }
2171
Peter Wang44b186e2020-01-13 23:33:09 -08002172 private boolean isImsAvailableOnDevice() {
2173 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2174 if (pm == null) {
2175 // For some reason package manger is not available.. This will fail internally anyway,
2176 // so do not throw error and allow.
2177 return true;
2178 }
2179 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2180 }
2181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002183 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
Wink Savilleb564aae2014-10-23 10:18:09 -07002186 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 if (DBG) log("dial: " + number);
2188 // No permission check needed here: This is just a wrapper around the
2189 // ACTION_DIAL intent, which is available to any app since it puts up
2190 // the UI before it does anything.
2191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 String url = createTelUrl(number);
2195 if (url == null) {
2196 return;
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002199 // PENDING: should we just silently fail if phone is offhook or ringing?
2200 PhoneConstants.State state = mCM.getState(subId);
2201 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2202 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2203 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2204 mApp.startActivity(intent);
2205 }
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 }
2209 }
2210
2211 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002212 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002213 }
2214
Wink Savilleb564aae2014-10-23 10:18:09 -07002215 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 if (DBG) log("call: " + number);
2217
2218 // This is just a wrapper around the ACTION_CALL intent, but we still
2219 // need to do a permission check since we're calling startActivity()
2220 // from the context of the phone app.
2221 enforceCallPermission();
2222
Jordan Liu1617b712019-07-10 15:06:26 -07002223 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 != AppOpsManager.MODE_ALLOWED) {
2225 return;
2226 }
2227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 String url = createTelUrl(number);
2231 if (url == null) {
2232 return;
2233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235 boolean isValid = false;
2236 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2237 if (slist != null) {
2238 for (SubscriptionInfo subInfoRecord : slist) {
2239 if (subInfoRecord.getSubscriptionId() == subId) {
2240 isValid = true;
2241 break;
2242 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002243 }
Wink Saville08874612014-08-31 19:19:58 -07002244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 if (!isValid) {
2246 return;
2247 }
Wink Saville08874612014-08-31 19:19:58 -07002248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2250 intent.putExtra(SUBSCRIPTION_KEY, subId);
2251 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2252 mApp.startActivity(intent);
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
Wink Savilleb564aae2014-10-23 10:18:09 -07002258 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002259 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002260 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2261 }
2262
Wink Savilleb564aae2014-10-23 10:18:09 -07002263 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002264 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002265 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2266 }
2267
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270
2271 final long identity = Binder.clearCallingIdentity();
2272 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002273 Phone phone = getPhone(subId);
2274 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 checkSimPin.start();
2276 return checkSimPin.unlockSim(null, pin);
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
Wink Savilleb564aae2014-10-23 10:18:09 -07002282 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002287 Phone phone = getPhone(subId);
2288 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 checkSimPuk.start();
2290 return checkSimPuk.unlockSim(puk, pin);
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002297 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 * a synchronous one.
2299 */
2300 private static class UnlockSim extends Thread {
2301
2302 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002303 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304
2305 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002306 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2307 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308
2309 // For replies from SimCard interface
2310 private Handler mHandler;
2311
2312 // For async handler to identify request type
2313 private static final int SUPPLY_PIN_COMPLETE = 100;
2314
Michele Berionne5e411512020-11-13 02:36:59 +00002315 UnlockSim(int phoneId, IccCard simCard) {
2316 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 mSimCard = simCard;
2318 }
2319
2320 @Override
2321 public void run() {
2322 Looper.prepare();
2323 synchronized (UnlockSim.this) {
2324 mHandler = new Handler() {
2325 @Override
2326 public void handleMessage(Message msg) {
2327 AsyncResult ar = (AsyncResult) msg.obj;
2328 switch (msg.what) {
2329 case SUPPLY_PIN_COMPLETE:
2330 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2331 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002332 mRetryCount = msg.arg1;
2333 if (ar.exception != null) {
2334 if (ar.exception instanceof CommandException &&
2335 ((CommandException)(ar.exception)).getCommandError()
2336 == CommandException.Error.PASSWORD_INCORRECT) {
2337 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002338 } //When UiccCardApp dispose,handle message and return exception
2339 else if (ar.exception instanceof CommandException &&
2340 ((CommandException) (ar.exception)).getCommandError()
2341 == CommandException.Error.ABORTED) {
2342 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002343 } else {
2344 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2345 }
2346 } else {
2347 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 mDone = true;
2350 UnlockSim.this.notifyAll();
2351 }
2352 break;
2353 }
2354 }
2355 };
2356 UnlockSim.this.notifyAll();
2357 }
2358 Looper.loop();
2359 }
2360
2361 /*
2362 * Use PIN or PUK to unlock SIM card
2363 *
2364 * If PUK is null, unlock SIM card with PIN
2365 *
2366 * If PUK is not null, unlock SIM card with PUK and set PIN code
2367 */
Wink Saville9de0f752013-10-22 19:04:03 -07002368 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369
2370 while (mHandler == null) {
2371 try {
2372 wait();
2373 } catch (InterruptedException e) {
2374 Thread.currentThread().interrupt();
2375 }
2376 }
2377 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2378
2379 if (puk == null) {
2380 mSimCard.supplyPin(pin, callback);
2381 } else {
2382 mSimCard.supplyPuk(puk, pin, callback);
2383 }
2384
2385 while (!mDone) {
2386 try {
2387 Log.d(LOG_TAG, "wait for done");
2388 wait();
2389 } catch (InterruptedException e) {
2390 // Restore the interrupted status
2391 Thread.currentThread().interrupt();
2392 }
2393 }
2394 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002395 int[] resultArray = new int[2];
2396 resultArray[0] = mResult;
2397 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002398
2399 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2400 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2401 }
2402
Wink Saville9de0f752013-10-22 19:04:03 -07002403 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405 }
2406
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002407 /**
2408 * This method has been removed due to privacy and stability concerns.
2409 */
2410 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002412 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2413 return;
Wink Saville36469e72014-06-11 15:17:00 -07002414 }
2415
Nathan Harold1f889d82020-06-04 17:05:26 -07002416 @Override
2417 public void updateServiceLocationWithPackageName(String callingPackage) {
2418 mApp.getSystemService(AppOpsManager.class)
2419 .checkPackage(Binder.getCallingUid(), callingPackage);
2420
Nathan Haroldf096d982020-11-18 17:18:06 -08002421 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002422 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2423 // Callers targeting S have no business invoking this method.
2424 return;
2425 }
2426
2427 LocationAccessPolicy.LocationPermissionResult locationResult =
2428 LocationAccessPolicy.checkLocationPermission(mApp,
2429 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2430 .setCallingPackage(callingPackage)
2431 .setCallingFeatureId(null)
2432 .setCallingPid(Binder.getCallingPid())
2433 .setCallingUid(Binder.getCallingUid())
2434 .setMethod("updateServiceLocation")
2435 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2436 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2437 .build());
2438 // Apps that lack location permission have no business calling this method;
2439 // however, because no permission was declared in the public API, denials must
2440 // all be "soft".
2441 switch (locationResult) {
2442 case DENIED_HARD: /* fall through */
2443 case DENIED_SOFT:
2444 return;
2445 }
2446
2447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002450 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002452 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002459 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 @Override
2461 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002462 return isRadioOnWithFeature(callingPackage, null);
2463 }
2464
2465
2466 @Override
2467 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2468 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2469 callingFeatureId);
2470 }
2471
2472 @Deprecated
2473 @Override
2474 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2475 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002476 }
2477
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002479 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2480 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002482 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002483 return false;
2484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002485
2486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 return isRadioOnForSubscriber(subId);
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
2491 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 }
2493
2494 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 final Phone phone = getPhone(subId);
2498 if (phone != null) {
2499 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2500 } else {
2501 return false;
2502 }
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507
2508 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002509 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
Wink Saville36469e72014-06-11 15:17:00 -07002511
Wink Savilleb564aae2014-10-23 10:18:09 -07002512 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 final Phone phone = getPhone(subId);
2518 if (phone != null) {
2519 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2520 }
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 }
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
2525
2526 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002527 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002528 }
2529
Wink Savilleb564aae2014-10-23 10:18:09 -07002530 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 final Phone phone = getPhone(subId);
2536 if (phone == null) {
2537 return false;
2538 }
2539 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2540 toggleRadioOnOffForSubscriber(subId);
2541 }
2542 return true;
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
Wink Saville36469e72014-06-11 15:17:00 -07002547
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002548 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002549 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002550 /*
2551 * If any of the Radios are available, it will need to be
2552 * shutdown. So return true if any Radio is available.
2553 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2557 Phone phone = PhoneFactory.getPhone(i);
2558 if (phone != null && phone.isRadioAvailable()) return true;
2559 }
2560 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2561 return false;
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002564 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002565 }
2566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002568 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569 enforceModifyPermission();
2570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2574 logv("Shutting down Phone " + i);
2575 shutdownRadioUsingPhoneId(i);
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002579 }
2580 }
2581
2582 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002583 Phone phone = PhoneFactory.getPhone(phoneId);
2584 if (phone != null && phone.isRadioAvailable()) {
2585 phone.shutdownRadio();
2586 }
2587 }
2588
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2595 if (defaultPhone != null) {
2596 defaultPhone.setRadioPower(turnOn);
2597 return true;
2598 } else {
2599 loge("There's no default phone.");
2600 return false;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002604 }
Wink Saville36469e72014-06-11 15:17:00 -07002605 }
2606
Wink Savilleb564aae2014-10-23 10:18:09 -07002607 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 final Phone phone = getPhone(subId);
2613 if (phone != null) {
2614 phone.setRadioPower(turnOn);
2615 return true;
2616 } else {
2617 return false;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
Wink Saville36469e72014-06-11 15:17:00 -07002624 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002625 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 public boolean enableDataConnectivity() {
2627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 int subId = mSubscriptionController.getDefaultDataSubId();
2632 final Phone phone = getPhone(subId);
2633 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002634 phone.getDataEnabledSettings().setDataEnabled(
2635 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 return true;
2637 } else {
2638 return false;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
Wink Saville36469e72014-06-11 15:17:00 -07002645 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 public boolean disableDataConnectivity() {
2648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 int subId = mSubscriptionController.getDefaultDataSubId();
2653 final Phone phone = getPhone(subId);
2654 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002655 phone.getDataEnabledSettings().setDataEnabled(
2656 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 return true;
2658 } else {
2659 return false;
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
2665
Sanket Padawe356d7632015-06-22 14:03:32 -07002666 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002667 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002672 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673 } else {
2674 return false;
2675 }
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
2681 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002682 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002683 }
2684
pkanwarae03a6b2016-11-06 20:37:09 -08002685 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 enforceCallPermission();
2687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2691 return;
2692 }
2693 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2694 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
pkanwar32d516d2016-10-14 19:37:38 -07002698 };
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2706 return false;
2707 }
2708 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 }
2713
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002715 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002716 }
2717
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002718 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 Phone phone = PhoneFactory.getPhone(slotIndex);
2722 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2723 PhoneConstantConversions.convertCallState(phone.getState());
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
2728
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002730 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002731 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2732 }
2733
2734 @Override
2735 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 if (phone != null) {
2740 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2741 } else {
2742 return PhoneConstantConversions.convertDataState(
2743 PhoneConstants.DataState.DISCONNECTED);
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
2749
Sanket Padawe356d7632015-06-22 14:03:32 -07002750 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002751 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002752 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2753 }
2754
2755 @Override
2756 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002759 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 if (phone != null) {
2761 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2762 } else {
2763 return TelephonyManager.DATA_ACTIVITY_NONE;
2764 }
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769
2770 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002771 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002772 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002773 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002774
2775 LocationAccessPolicy.LocationPermissionResult locationResult =
2776 LocationAccessPolicy.checkLocationPermission(mApp,
2777 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2778 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002779 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002780 .setCallingPid(Binder.getCallingPid())
2781 .setCallingUid(Binder.getCallingUid())
2782 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002783 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002784 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2785 .build());
2786 switch (locationResult) {
2787 case DENIED_HARD:
2788 throw new SecurityException("Not allowed to access cell location");
2789 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002790 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2791 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002794 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002798 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002799 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800 } finally {
2801 Binder.restoreCallingIdentity(identity);
2802 }
Svetoslav64fad262015-04-14 14:35:21 -07002803 }
2804
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002806 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002807 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2808 // registered cell info, so return a NULL country instead.
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002811 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2812 // Get default phone in this case.
2813 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2814 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002815 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002817 if (phone == null) return "";
2818 ServiceStateTracker sst = phone.getServiceStateTracker();
2819 if (sst == null) return "";
2820 LocaleTracker lt = sst.getLocaleTracker();
2821 if (lt == null) return "";
2822 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2823 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2824 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002825 } finally {
2826 Binder.restoreCallingIdentity(identity);
2827 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002828 }
2829
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002830 /**
2831 * This method was removed due to potential issues caused by performing partial
2832 * updates of service state, and lack of a credible use case.
2833 *
2834 * This has the ability to break the telephony implementation by disabling notification of
2835 * changes in device connectivity. DO NOT USE THIS!
2836 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002837 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 public void enableLocationUpdates() {
2839 mApp.enforceCallingOrSelfPermission(
2840 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002843 /**
2844 * This method was removed due to potential issues caused by performing partial
2845 * updates of service state, and lack of a credible use case.
2846 *
2847 * This has the ability to break the telephony implementation by disabling notification of
2848 * changes in device connectivity. DO NOT USE THIS!
2849 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 @Override
2851 public void disableLocationUpdates() {
2852 mApp.enforceCallingOrSelfPermission(
2853 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 }
2855
2856 @Override
2857 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002858 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2859 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002860 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002861 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2862 throw new SecurityException(
2863 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2864 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002865
Jordan Liu1617b712019-07-10 15:06:26 -07002866 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2868 return null;
2869 }
Svetoslav64fad262015-04-14 14:35:21 -07002870
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002871 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002873 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002874 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875
Nathan Haroldf180aac2018-06-01 18:43:55 -07002876 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2877 for (CellInfo ci : info) {
2878 if (ci instanceof CellInfoGsm) {
2879 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2880 } else if (ci instanceof CellInfoWcdma) {
2881 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002884 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 }
2886
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002887 private List<CellInfo> getCachedCellInfo() {
2888 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2889 for (Phone phone : PhoneFactory.getPhones()) {
2890 List<CellInfo> info = phone.getAllCellInfo();
2891 if (info != null) cellInfos.addAll(info);
2892 }
2893 return cellInfos;
2894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895
2896 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002897 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002898 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002899 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002900
2901 LocationAccessPolicy.LocationPermissionResult locationResult =
2902 LocationAccessPolicy.checkLocationPermission(mApp,
2903 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2904 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002905 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002906 .setCallingPid(Binder.getCallingPid())
2907 .setCallingUid(Binder.getCallingUid())
2908 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002910 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2911 .build());
2912 switch (locationResult) {
2913 case DENIED_HARD:
2914 throw new SecurityException("Not allowed to access cell info");
2915 case DENIED_SOFT:
2916 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 }
2918
Nathan Haroldf096d982020-11-18 17:18:06 -08002919 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002920 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2921 return getCachedCellInfo();
2922 }
2923
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002924 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2929 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002930 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002931 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 if (info != null) cellInfos.addAll(info);
2933 }
2934 return cellInfos;
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
2938 }
2939
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002940 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002941 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2942 String callingFeatureId) {
2943 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2944 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002945 }
2946
2947 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002948 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2949 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002950 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002951 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002952 }
2953
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002954 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2955 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002957 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002958
2959 LocationAccessPolicy.LocationPermissionResult locationResult =
2960 LocationAccessPolicy.checkLocationPermission(mApp,
2961 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2962 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002963 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .setCallingPid(Binder.getCallingPid())
2965 .setCallingUid(Binder.getCallingUid())
2966 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002967 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2968 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002969 .build());
2970 switch (locationResult) {
2971 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002972 if (TelephonyPermissions
2973 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002974 // Safetynet logging for b/154934934
2975 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2976 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002977 throw new SecurityException("Not allowed to access cell info");
2978 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002979 if (TelephonyPermissions
2980 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002981 // Safetynet logging for b/154934934
2982 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2983 }
Nathan Harold5320c422019-05-09 10:26:08 -07002984 try {
2985 cb.onCellInfo(new ArrayList<CellInfo>());
2986 } catch (RemoteException re) {
2987 // Drop without consequences
2988 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002989 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002990 }
2991
Nathan Harolda939a962019-05-09 10:13:47 -07002992
2993 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002994 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2995
2996 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2997 }
2998
2999 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003001 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
Shishir Agrawala9f32182016-04-12 12:00:16 -07003012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003013 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003014 Phone phone = PhoneFactory.getPhone(slotIndex);
3015 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 return null;
3017 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003018 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003019 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003020 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003021 return null;
3022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 return phone.getImei();
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003030 }
3031
3032 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003033 public String getTypeAllocationCodeForSlot(int slotIndex) {
3034 Phone phone = PhoneFactory.getPhone(slotIndex);
3035 String tac = null;
3036 if (phone != null) {
3037 String imei = phone.getImei();
3038 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3039 }
3040 return tac;
3041 }
3042
3043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003044 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003045 Phone phone = PhoneFactory.getPhone(slotIndex);
3046 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003047 return null;
3048 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049
Jeff Davidson913390f2018-02-23 17:11:49 -08003050 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003051 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003052 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003053 return null;
3054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 return phone.getMeid();
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
Jack Yu2af8d712017-03-15 17:14:14 -07003062 }
3063
3064 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003065 public String getManufacturerCodeForSlot(int slotIndex) {
3066 Phone phone = PhoneFactory.getPhone(slotIndex);
3067 String manufacturerCode = null;
3068 if (phone != null) {
3069 String meid = phone.getMeid();
3070 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3071 }
3072 return manufacturerCode;
3073 }
3074
3075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003076 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3077 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003078 Phone phone = PhoneFactory.getPhone(slotIndex);
3079 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003080 return null;
3081 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003082 int subId = phone.getSubId();
3083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003084 mApp, subId, callingPackage, callingFeatureId,
3085 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003086 return null;
3087 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 return phone.getDeviceSvn();
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003095 }
3096
fionaxu43304da2017-11-27 22:51:16 -08003097 @Override
3098 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 final Phone phone = getPhone(subId);
3102 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
fionaxu43304da2017-11-27 22:51:16 -08003106 }
3107
3108 @Override
3109 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 final Phone phone = getPhone(subId);
3113 return phone == null ? null : phone.getCarrierName();
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
fionaxu43304da2017-11-27 22:51:16 -08003117 }
3118
calvinpanffe225e2018-11-01 19:43:06 +08003119 @Override
chen xu0026ca62019-03-06 15:28:50 -08003120 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 final Phone phone = getPhone(subId);
3124 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003125 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003126 } finally {
3127 Binder.restoreCallingIdentity(identity);
3128 }
3129 }
3130
3131 @Override
chen xu0026ca62019-03-06 15:28:50 -08003132 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003136 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
chen xu651eec72018-11-11 19:03:44 -08003142 @Override
chen xu864e11c2018-12-06 22:10:03 -08003143 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3144 if (!isSubscriptionMccMnc) {
3145 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3146 }
chen xu651eec72018-11-11 19:03:44 -08003147 final Phone phone = PhoneFactory.getPhone(slotIndex);
3148 if (phone == null) {
3149 return TelephonyManager.UNKNOWN_CARRIER_ID;
3150 }
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 //
3160 // Internal helper methods.
3161 //
3162
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003163 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3165 *
3166 * @throws SecurityException if the caller does not have the required permission
3167 */
3168 private void enforceModifyPermission() {
3169 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3170 }
3171
Shuo Qiancd19c462020-01-16 20:51:11 -08003172 /**
3173 * Make sure the caller is system.
3174 *
3175 * @throws SecurityException if the caller is not system.
3176 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003177 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003178 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3179 throw new SecurityException("Caller must be system");
3180 }
3181 }
3182
Shuo Qian3b6ee772019-11-13 17:43:31 -08003183 private void enforceActiveEmergencySessionPermission() {
3184 mApp.enforceCallingOrSelfPermission(
3185 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3186 }
3187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 /**
3189 * Make sure the caller has the CALL_PHONE permission.
3190 *
3191 * @throws SecurityException if the caller does not have the required permission
3192 */
3193 private void enforceCallPermission() {
3194 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3195 }
3196
paulhu5a773602019-08-23 19:17:33 +08003197 private void enforceSettingsPermission() {
3198 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003199 }
3200
Michele Berionne5e411512020-11-13 02:36:59 +00003201 private void enforceRebootPermission() {
3202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3203 }
3204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 private String createTelUrl(String number) {
3206 if (TextUtils.isEmpty(number)) {
3207 return null;
3208 }
3209
Jake Hambye994d462014-02-03 13:10:13 -08003210 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212
Ihab Awadf9e92732013-12-05 18:02:52 -08003213 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3215 }
3216
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003217 private static void logv(String msg) {
3218 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3219 }
3220
Ihab Awadf9e92732013-12-05 18:02:52 -08003221 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3223 }
3224
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003225 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003226 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003227 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003228 }
3229
Sanket Padawe356d7632015-06-22 14:03:32 -07003230 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003231 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 final Phone phone = PhoneFactory.getPhone(slotIndex);
3235 if (phone == null) {
3236 return PhoneConstants.PHONE_TYPE_NONE;
3237 } else {
3238 return phone.getPhoneType();
3239 }
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 }
3244
3245 /**
3246 * Returns the CDMA ERI icon index to display
3247 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003248 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003249 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3250 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3251 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003252 }
3253
Sanket Padawe356d7632015-06-22 14:03:32 -07003254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003255 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3256 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003258 mApp, subId, callingPackage, callingFeatureId,
3259 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003260 return -1;
3261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 final Phone phone = getPhone(subId);
3266 if (phone != null) {
3267 return phone.getCdmaEriIconIndex();
3268 } else {
3269 return -1;
3270 }
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 }
3275
3276 /**
3277 * Returns the CDMA ERI icon mode,
3278 * 0 - ON
3279 * 1 - FLASHING
3280 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003282 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3283 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3284 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003285 }
3286
Sanket Padawe356d7632015-06-22 14:03:32 -07003287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3289 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003291 mApp, subId, callingPackage, callingFeatureId,
3292 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003293 return -1;
3294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 final Phone phone = getPhone(subId);
3299 if (phone != null) {
3300 return phone.getCdmaEriIconMode();
3301 } else {
3302 return -1;
3303 }
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 }
3308
3309 /**
3310 * Returns the CDMA ERI text,
3311 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003312 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003313 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3314 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3315 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003316 }
3317
Sanket Padawe356d7632015-06-22 14:03:32 -07003318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003319 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3320 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003322 mApp, subId, callingPackage, callingFeatureId,
3323 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003324 return null;
3325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
3330 if (phone != null) {
3331 return phone.getCdmaEriText();
3332 } else {
3333 return null;
3334 }
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003338 }
3339
3340 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003341 * Returns the CDMA MDN.
3342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003344 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003351 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 return phone.getLine1Number();
3353 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003354 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 return null;
3356 }
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003359 }
3360 }
3361
3362 /**
3363 * Returns the CDMA MIN.
3364 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003365 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003366 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3368 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 final Phone phone = getPhone(subId);
3373 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3374 return phone.getCdmaMin();
3375 } else {
3376 return null;
3377 }
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003380 }
3381 }
3382
Hall Liud892bec2018-11-30 14:51:45 -08003383 @Override
3384 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3385 INumberVerificationCallback callback, String callingPackage) {
3386 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3387 != PERMISSION_GRANTED) {
3388 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3389 }
3390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3391
3392 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3393 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003394 throw new SecurityException("Calling package must be configured in the device config: "
3395 + "calling package: " + callingPackage
3396 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003397 }
3398
3399 if (range == null) {
3400 throw new NullPointerException("Range must be non-null");
3401 }
3402
3403 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003404 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003405
3406 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3407 }
3408
Junda Liuca05d5d2014-08-14 22:36:34 -07003409 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003410 * Returns true if CDMA provisioning needs to run.
3411 */
3412 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 final long identity = Binder.clearCallingIdentity();
3414 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003415 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419 }
3420
3421 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003422 * Sets the voice mail number of a given subId.
3423 */
3424 @Override
3425 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003426 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3427 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3432 new Pair<String, String>(alphaTag, number), new Integer(subId));
3433 return success;
3434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003437 }
3438
Ta-wei Yen87c49842016-05-13 21:19:52 -07003439 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003440 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3441 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003442 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3443 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003444 if (!TextUtils.equals(callingPackage, systemDialer)) {
3445 throw new SecurityException("caller must be system dialer");
3446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3451 if (phoneAccountHandle == null) {
3452 return null;
3453 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003454 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455 } finally {
3456 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003457 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003458 }
3459
3460 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003461 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3462 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003465 mApp, subId, callingPackage, callingFeatureId,
3466 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003467 return null;
3468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003472 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003473 } finally {
3474 Binder.restoreCallingIdentity(identity);
3475 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003476 }
3477
3478 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003479 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3480 VisualVoicemailSmsFilterSettings settings) {
3481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003486 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003490 }
3491
3492 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003493 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3494 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003499 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003503 }
3504
3505 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003506 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3507 String callingPackage, int subId) {
3508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003513 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003517 }
3518
3519 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003520 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003526 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003530 }
3531
3532 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003533 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3534 String callingAttributionTag, int subId, String number, int port, String text,
3535 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003537 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003538 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003539 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003540 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3541 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003542 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003543
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003544 /**
fionaxu0152e512016-11-14 13:36:14 -08003545 * Sets the voice activation state of a given subId.
3546 */
3547 @Override
3548 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3550 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 final Phone phone = getPhone(subId);
3555 if (phone != null) {
3556 phone.setVoiceActivationState(activationState);
3557 } else {
3558 loge("setVoiceActivationState fails with invalid subId: " + subId);
3559 }
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003562 }
3563 }
3564
3565 /**
3566 * Sets the data activation state of a given subId.
3567 */
3568 @Override
3569 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3571 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 phone.setDataActivationState(activationState);
3578 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003579 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003583 }
3584 }
3585
3586 /**
3587 * Returns the voice activation state of a given subId.
3588 */
3589 @Override
3590 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592
fionaxu0152e512016-11-14 13:36:14 -08003593 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 if (phone != null) {
3597 return phone.getVoiceActivationState();
3598 } else {
3599 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3600 }
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003603 }
3604 }
3605
3606 /**
3607 * Returns the data activation state of a given subId.
3608 */
3609 @Override
3610 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612
fionaxu0152e512016-11-14 13:36:14 -08003613 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 if (phone != null) {
3617 return phone.getDataActivationState();
3618 } else {
3619 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3620 }
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003623 }
3624 }
3625
3626 /**
Wink Saville36469e72014-06-11 15:17:00 -07003627 * Returns the unread count of voicemails for a subId
3628 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003630 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3631 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003633 mApp, subId, callingPackage, callingFeatureId,
3634 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003635 return 0;
3636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 final Phone phone = getPhone(subId);
3640 if (phone != null) {
3641 return phone.getVoiceMessageCount();
3642 } else {
3643 return 0;
3644 }
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
3649
3650 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003651 * returns true, if the device is in a state where both voice and data
3652 * are supported simultaneously. This can change based on location or network condition.
3653 */
3654 @Override
3655 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 final Phone phone = getPhone(subId);
3659 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003663 }
3664
3665 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003666 * Send the dialer code if called from the current default dialer or the caller has
3667 * carrier privilege.
3668 * @param inputCode The dialer code to send
3669 */
3670 @Override
3671 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003674 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3675 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003676 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003677 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003683 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
fionaxu235cc5e2017-03-06 22:25:57 -08003687 }
3688
Pengquan Menga1bb6272018-09-06 09:59:22 -07003689 @Override
3690 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003691 TelephonyPermissions
3692 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3693 mApp, subId, "getNetworkSelectionMode");
3694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 if (!isActiveSubscription(subId)) {
3697 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3698 }
3699 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003703 }
3704
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003706 public boolean isInEmergencySmsMode() {
3707 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 for (Phone phone : PhoneFactory.getPhones()) {
3711 if (phone.isInEmergencySmsMode()) {
3712 return true;
3713 }
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
3718 return false;
3719 }
3720
shilu366312e2019-12-17 09:28:10 -08003721 /**
3722 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3723 * @param subId The subscription to use to check the configuration.
3724 * @param c The callback that will be used to send the result.
3725 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003726 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003727 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3728 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003729 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3730 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003731
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003732 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3734 "IMS not available on device.");
3735 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 final long token = Binder.clearCallingIdentity();
3737 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (ImsException e) {
3742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 } finally {
3744 Binder.restoreCallingIdentity(token);
3745 }
3746 }
3747
shilu366312e2019-12-17 09:28:10 -08003748 /**
3749 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3750 * @param subId The subscription to use to check the configuration.
3751 * @param c The callback that will be used to send the result.
3752 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003754 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003755 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3756 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3758 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3759 }
Meng Wangafbc5852019-09-19 17:37:13 -07003760 final long token = Binder.clearCallingIdentity();
3761 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003762 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003763 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3764 .removeRegistrationCallbackForSubscription(c, subId);
3765 } catch (ImsException e) {
3766 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3767 + "is inactive, ignoring unregister.");
3768 // If the subscription is no longer active, just return, since the callback
3769 // will already have been removed internally.
3770 } finally {
3771 Binder.restoreCallingIdentity(token);
3772 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 }
3774
Brad Ebingera34a6c22019-10-22 17:36:18 -07003775 /**
3776 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3777 */
3778 @Override
3779 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3780 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3781 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3783 "IMS not available on device.");
3784 }
3785 final long token = Binder.clearCallingIdentity();
3786 try {
3787 Phone phone = getPhone(subId);
3788 if (phone == null) {
3789 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3790 + subId + "'");
3791 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3792 }
3793 phone.getImsRegistrationState(regState -> {
3794 try {
3795 consumer.accept((regState == null)
3796 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3797 } catch (RemoteException e) {
3798 // Ignore if the remote process is no longer available to call back.
3799 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3800 }
3801 });
3802 } finally {
3803 Binder.restoreCallingIdentity(token);
3804 }
3805 }
3806
3807 /**
3808 * Get the transport type for the IMS service registration state.
3809 */
3810 @Override
3811 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003812 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3813 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003814 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3815 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3816 "IMS not available on device.");
3817 }
3818 final long token = Binder.clearCallingIdentity();
3819 try {
3820 Phone phone = getPhone(subId);
3821 if (phone == null) {
3822 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3823 + subId + "'");
3824 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3825 }
3826 phone.getImsRegistrationTech(regTech -> {
3827 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3828 int regTechConverted = (regTech == null)
3829 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3830 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3831 regTechConverted);
3832 try {
3833 consumer.accept(regTechConverted);
3834 } catch (RemoteException e) {
3835 // Ignore if the remote process is no longer available to call back.
3836 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3837 }
3838 });
3839 } finally {
3840 Binder.restoreCallingIdentity(token);
3841 }
3842 }
3843
shilu366312e2019-12-17 09:28:10 -08003844 /**
3845 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3846 * @param subId The subscription to use to check the configuration.
3847 * @param c The callback that will be used to send the result.
3848 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003850 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3851 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003852 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3853 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003854 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3855 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3856 "IMS not available on device.");
3857 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3859 final long token = Binder.clearCallingIdentity();
3860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003861 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (ImsException e) {
3864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 } finally {
3866 Binder.restoreCallingIdentity(token);
3867 }
3868 }
3869
shilu366312e2019-12-17 09:28:10 -08003870 /**
3871 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3872 * @param subId The subscription to use to check the configuration.
3873 * @param c The callback that will be used to send the result.
3874 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003876 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003877 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3878 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3880 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3881 }
Meng Wangafbc5852019-09-19 17:37:13 -07003882
3883 final long token = Binder.clearCallingIdentity();
3884 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003885 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003886 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003887 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003888 } catch (ImsException e) {
3889 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3890 + "is inactive, ignoring unregister.");
3891 // If the subscription is no longer active, just return, since the callback
3892 // will already have been removed internally.
3893 } finally {
3894 Binder.restoreCallingIdentity(token);
3895 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 }
3897
3898 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003899 public boolean isCapable(int subId, int capability, int regTech) {
3900 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3902 final long token = Binder.clearCallingIdentity();
3903 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003904 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003906 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3908 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003909 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003910 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3911 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 } finally {
3913 Binder.restoreCallingIdentity(token);
3914 }
3915 }
3916
3917 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003918 public boolean isAvailable(int subId, int capability, int regTech) {
3919 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 final long token = Binder.clearCallingIdentity();
3921 try {
3922 Phone phone = getPhone(subId);
3923 if (phone == null) return false;
3924 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003925 } catch (com.android.ims.ImsException e) {
3926 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3927 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 } finally {
3929 Binder.restoreCallingIdentity(token);
3930 }
3931 }
3932
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003933 /**
3934 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3935 * subscription.
3936 * @param subId The subscription to use to check the configuration.
3937 * @param callback The callback that will be used to send the result.
3938 * @param capability The MmTelFeature capability that will be used to send the result.
3939 * @param transportType The transport type of the MmTelFeature capability.
3940 */
3941 @Override
3942 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3943 int transportType) {
3944 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3945 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3947 "IMS not available on device.");
3948 }
3949 final long token = Binder.clearCallingIdentity();
3950 try {
3951 int slotId = getSlotIndex(subId);
3952 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3953 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3954 + subId + "'");
3955 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3956 }
3957 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3958 transportType, aBoolean -> {
3959 try {
3960 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3961 } catch (RemoteException e) {
3962 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3963 + "running. Ignore");
3964 }
3965 });
3966 } finally {
3967 Binder.restoreCallingIdentity(token);
3968 }
3969 }
3970
shilu366312e2019-12-17 09:28:10 -08003971 /**
3972 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3973 * @param subId The subscription to use to check the configuration.
3974 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 @Override
3976 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003977 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3978 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003979
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3981 final long token = Binder.clearCallingIdentity();
3982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003985 } catch (ImsException e) {
3986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 } finally {
3988 Binder.restoreCallingIdentity(token);
3989 }
3990 }
3991
3992 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003993 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003995 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003999 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004001 } catch (ImsException e) {
4002 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 } finally {
4004 Binder.restoreCallingIdentity(identity);
4005 }
4006 }
4007
shilu366312e2019-12-17 09:28:10 -08004008 /**
4009 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4010 * @param subId The subscription to use to check the configuration.
4011 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004013 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004014 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4015 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004019 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4020 } catch (ImsException e) {
4021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025 }
4026
4027 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004028 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004030 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004034 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004035 } catch (ImsException e) {
4036 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
4040 }
4041
shilu366312e2019-12-17 09:28:10 -08004042 /**
4043 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4044 * @param subId The subscription to use to check the configuration.
4045 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 @Override
4047 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004048 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4049 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004053 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
4060 }
4061
4062 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004063 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004065 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004069 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004070 } catch (ImsException e) {
4071 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
4075 }
4076
shilu366312e2019-12-17 09:28:10 -08004077 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004078 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4080 * @param subId The subscription to use to check the configuration.
4081 */
4082 @Override
4083 public boolean isCrossSimCallingEnabledByUser(int subId) {
4084 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4085 mApp, subId, "isCrossSimCallingEnabledByUser");
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4089 return ImsManager.getInstance(mApp,
4090 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
4093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
4096 }
4097
4098 /**
4099 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4100 * Requires MODIFY_PHONE_STATE permission.
4101 * @param subId The subscription to use to check the configuration.
4102 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4103 * false otherwise
4104 */
4105 @Override
4106 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4108 "setCrossSimCallingEnabled");
4109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4112 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4113 .setCrossSimCallingEnabled(isEnabled);
4114 } catch (ImsException e) {
4115 throw new ServiceSpecificException(e.getCode());
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
4119 }
4120
4121 /**
shilu366312e2019-12-17 09:28:10 -08004122 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4123 * @param subId The subscription to use to check the configuration.
4124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 @Override
4126 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004127 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4128 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004132 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004134 } catch (ImsException e) {
4135 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 } finally {
4137 Binder.restoreCallingIdentity(identity);
4138 }
4139 }
4140
4141 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004142 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004144 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004148 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (ImsException e) {
4151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4160 "setVoWiFiNonPersistent");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004165 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
shilu366312e2019-12-17 09:28:10 -08004173 /**
4174 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4175 * @param subId The subscription to use to check the configuration.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
4178 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4180 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004184 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
4193 @Override
4194 public void setVoWiFiModeSetting(int subId, int mode) {
4195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4196 "setVoWiFiModeSetting");
4197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004200 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
4209 @Override
4210 public int getVoWiFiRoamingModeSetting(int subId) {
4211 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
4224 @Override
4225 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4227 "setVoWiFiRoamingModeSetting");
4228 final long identity = Binder.clearCallingIdentity();
4229 try {
4230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004231 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004233 } catch (ImsException e) {
4234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
4238 }
4239
4240 @Override
4241 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4243 "setRttCapabilityEnabled");
4244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004247 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4248 } catch (ImsException e) {
4249 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
shilu366312e2019-12-17 09:28:10 -08004255 /**
4256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4257 * @param subId The subscription to use to check the configuration.
4258 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 @Override
4260 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004261 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4262 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004266 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004268 } catch (ImsException e) {
4269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
4273 }
4274
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004275 @Override
4276 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4277 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004280 if (!isImsAvailableOnDevice()) {
4281 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4282 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004283 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004286 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004287 } catch (ImsException e) {
4288 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
4292 }
4293
4294 @Override
4295 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4296 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4297 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004298 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4299 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4300 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004301 try {
4302 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004303 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004304 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004305 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004306 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4307 + "is inactive, ignoring unregister.");
4308 // If the subscription is no longer active, just return, since the callback will already
4309 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004310 } finally {
4311 Binder.restoreCallingIdentity(identity);
4312 }
4313 }
4314
allenwtsu99c623b2020-01-03 18:24:23 +08004315
4316 private void checkModifyPhoneStatePermission(int subId, String message) {
4317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4318 message);
4319 }
4320
4321 private boolean isImsProvisioningRequired(int subId, int capability,
4322 boolean isMmtelCapability) {
4323 Phone phone = getPhone(subId);
4324 if (phone == null) {
4325 loge("phone instance null for subid " + subId);
4326 return false;
4327 }
4328 if (isMmtelCapability) {
4329 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4330 return false;
4331 }
4332 } else {
4333 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4334 return false;
4335 }
4336 }
4337 return true;
4338 }
4339
4340 @Override
4341 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4342 boolean isProvisioned) {
4343 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4344
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4348 if (!isImsProvisioningRequired(subId, capability, false)) {
4349 return;
4350 }
4351
4352 // this capability requires provisioning, route to the correct API.
4353 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4354 switch (capability) {
4355 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4356 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4357 ims.setEabProvisioned(isProvisioned);
4358 break;
4359 default: {
4360 throw new IllegalArgumentException("Tried to set provisioning for "
4361 + "rcs capability '" + capability + "', which does not require "
4362 + "provisioning.");
4363 }
4364 }
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368
4369 }
4370
4371
4372 @Override
4373 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4374 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4378 if (!isImsProvisioningRequired(subId, capability, false)) {
4379 return true;
4380 }
4381
4382 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4383 switch (capability) {
4384 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4385 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4386 return ims.isEabProvisionedOnDevice();
4387
4388 default: {
4389 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4390 + "capability '" + capability + "', which does not require "
4391 + "provisioning.");
4392 }
4393 }
4394
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
4398 }
4399
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004400 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004401 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4402 boolean isProvisioned) {
4403 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4404 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4405 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4406 }
allenwtsu99c623b2020-01-03 18:24:23 +08004407 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004411 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004412 return;
4413 }
4414
4415 // this capability requires provisioning, route to the correct API.
4416 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4417 switch (capability) {
4418 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4419 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4420 ims.setVolteProvisioned(isProvisioned);
4421 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4422 ims.setWfcProvisioned(isProvisioned);
4423 }
4424 break;
4425 }
4426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4427 // There is currently no difference in VT provisioning type.
4428 ims.setVtProvisioned(isProvisioned);
4429 break;
4430 }
4431 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4432 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4433 // change the capability of the feature instead if needed.
4434 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4435 == isProvisioned) {
4436 // No change in provisioning.
4437 return;
4438 }
4439 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4440 try {
4441 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004442 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004443 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4444 + ", Exception" + e.getMessage());
4445 }
4446 break;
4447 }
4448 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004449 throw new IllegalArgumentException("Tried to set provisioning for "
4450 + "MmTel capability '" + capability + "', which does not require "
4451 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004452 }
4453 }
4454
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
4460 @Override
4461 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4462 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4463 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4464 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4465 }
4466 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004470 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004471 return true;
4472 }
4473
4474 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4475 switch (capability) {
4476 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4477 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4478 return ims.isVolteProvisionedOnDevice();
4479 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4480 return ims.isWfcProvisionedOnDevice();
4481 }
4482 // This should never happen, since we are checking tech above to make sure it
4483 // is either LTE or IWLAN.
4484 throw new IllegalArgumentException("Invalid radio technology for voice "
4485 + "capability.");
4486 }
4487 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4488 // There is currently no difference in VT provisioning type.
4489 return ims.isVtProvisionedOnDevice();
4490 }
4491 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4492 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4493 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4494 }
4495 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004496 throw new IllegalArgumentException(
4497 "Tried to get provisioning for MmTel capability '" + capability
4498 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004499 }
4500 }
4501
4502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
4505 }
4506
4507 @Override
4508 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4509 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4510 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4511 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4512 }
4513 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4514 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4515 return (provisionedBits & capability) > 0;
4516 }
4517
4518 @Override
4519 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4520 boolean isProvisioned) {
4521 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4522 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4523 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4524 }
4525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4526 "setProvisioningStatusForCapability");
4527 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4528 // If the current provisioning status for capability already matches isProvisioned,
4529 // do nothing.
4530 if (((provisionedBits & capability) > 0) == isProvisioned) {
4531 return;
4532 }
4533 if (isProvisioned) {
4534 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4535 } else {
4536 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4537 }
4538 }
4539
4540 /**
4541 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4542 * technology. The bitfield should mirror the bitfield defined by
4543 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4544 */
4545 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4546 String key = getMmTelProvisioningKey(subId, tech);
4547 // Default is no capabilities are provisioned.
4548 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4549 }
4550
4551 /**
4552 * Sets the MmTel capability provisioning bitfield (defined by
4553 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4554 * technology specified.
4555 *
4556 * Note: This is a synchronous command and should not be called on UI thread.
4557 */
4558 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4559 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4560 String key = getMmTelProvisioningKey(subId, tech);
4561 editor.putInt(key, newField);
4562 editor.commit();
4563 }
4564
4565 private static String getMmTelProvisioningKey(int subId, int tech) {
4566 // resulting key is provision_ims_mmtel_{subId}_{tech}
4567 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4568 }
4569
4570 /**
4571 * Query CarrierConfig to see if the specified capability requires provisioning for the
4572 * carrier associated with the subscription id.
4573 */
4574 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4575 int capability) {
4576 CarrierConfigManager configManager = new CarrierConfigManager(context);
4577 PersistableBundle c = configManager.getConfigForSubId(subId);
4578 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004579 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4581 false);
4582 boolean requireVoiceVtProvisioning = c.getBoolean(
4583 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4584
4585 // First check to make sure that the capability requires provisioning.
4586 switch (capability) {
4587 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4588 // intentional fallthrough
4589 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4590 if (requireVoiceVtProvisioning) {
4591 // Voice and Video requires provisioning
4592 return true;
4593 }
4594 break;
4595 }
4596 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4597 if (requireUtProvisioning) {
4598 // UT requires provisioning
4599 return true;
4600 }
4601 break;
4602 }
4603 }
4604 return false;
4605 }
4606
allenwtsu99c623b2020-01-03 18:24:23 +08004607 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4608 int capability) {
4609 CarrierConfigManager configManager = new CarrierConfigManager(context);
4610 PersistableBundle c = configManager.getConfigForSubId(subId);
4611
4612 boolean requireRcsProvisioning = c.getBoolean(
4613 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4614
4615 // First check to make sure that the capability requires provisioning.
4616 switch (capability) {
4617 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4618 // intentional fallthrough
4619 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4620 if (requireRcsProvisioning) {
4621 // OPTION or PRESENCE requires provisioning
4622 return true;
4623 }
4624 break;
4625 }
4626 }
4627 return false;
4628 }
4629
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004630 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004631 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4633 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4634 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004635 enforceReadPrivilegedPermission("getImsProvisioningInt");
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 int slotId = getSlotIndex(subId);
4640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4641 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4642 + subId + "' for key:" + key);
4643 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4644 }
4645 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004646 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4648 + subId + "' for key:" + key);
4649 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
4655 @Override
4656 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4658 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4659 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004660 enforceReadPrivilegedPermission("getImsProvisioningString");
4661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 int slotId = getSlotIndex(subId);
4665 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4666 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4667 + subId + "' for key:" + key);
4668 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4669 }
4670 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004671 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4673 + subId + "' for key:" + key);
4674 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678 }
4679
4680 @Override
4681 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4683 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4684 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4686 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 int slotId = getSlotIndex(subId);
4691 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4692 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4693 + subId + "' for key:" + key);
4694 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4695 }
4696 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4699 + "' for key:" + key);
4700 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
4704 }
4705
4706 @Override
4707 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4709 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4710 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4712 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004716 int slotId = getSlotIndex(subId);
4717 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4718 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4719 + subId + "' for key:" + key);
4720 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4721 }
4722 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4725 + "' for key:" + key);
4726 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
4730 }
4731
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004732 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004733 int slotId = SubscriptionManager.getSlotIndex(subId);
4734 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004735 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4736 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 }
4738 return slotId;
4739 }
4740
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004741 private int getSlotIndex(int subId) {
4742 int slotId = SubscriptionManager.getSlotIndex(subId);
4743 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4744 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4745 }
4746 return slotId;
4747 }
4748
Wink Saville36469e72014-06-11 15:17:00 -07004749 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004750 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004751 */
4752 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004753 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4754 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004755 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004756 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004757 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004758 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004759 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004760 mApp, subId, callingPackage, callingFeatureId,
4761 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4763 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 final Phone phone = getPhone(subId);
4768 if (phone != null) {
4769 return phone.getServiceState().getDataNetworkType();
4770 } else {
4771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4772 }
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004776 }
4777
4778 /**
4779 * Returns the data network type
4780 */
4781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004782 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4783 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4784 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004785 }
4786
4787 /**
4788 * Returns the data network type for a subId
4789 */
4790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004791 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004794 mApp, subId, callingPackage, callingFeatureId,
4795 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004796 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4797 }
4798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 final Phone phone = getPhone(subId);
4802 if (phone != null) {
4803 return phone.getServiceState().getDataNetworkType();
4804 } else {
4805 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4806 }
4807 } finally {
4808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004810 }
4811
4812 /**
Wink Saville36469e72014-06-11 15:17:00 -07004813 * Returns the Voice network type for a subId
4814 */
4815 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004816 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4817 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004819 mApp, subId, callingPackage, callingFeatureId,
4820 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4822 }
4823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 final long identity = Binder.clearCallingIdentity();
4825 try {
4826 final Phone phone = getPhone(subId);
4827 if (phone != null) {
4828 return phone.getServiceState().getVoiceNetworkType();
4829 } else {
4830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4831 }
4832 } finally {
4833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004835 }
4836
4837 /**
4838 * @return true if a ICC card is present
4839 */
4840 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004841 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004842 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4843 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004844 }
4845
4846 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004847 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004848 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004849 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004850 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 final Phone phone = PhoneFactory.getPhone(slotIndex);
4854 if (phone != null) {
4855 return phone.getIccCard().hasIccCard();
4856 } else {
4857 return false;
4858 }
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004862 }
4863
4864 /**
4865 * Return if the current radio is LTE on CDMA. This
4866 * is a tri-state return value as for a period of time
4867 * the mode may be unknown.
4868 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004869 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004870 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004871 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004872 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004873 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004874 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4875 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4876 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004877 }
4878
Sanket Padawe356d7632015-06-22 14:03:32 -07004879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004880 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4881 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004882 try {
4883 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4884 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004885 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4886 }
4887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 final Phone phone = getPhone(subId);
4891 if (phone == null) {
4892 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4893 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004894 return TelephonyProperties.lte_on_cdma_device()
4895 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 }
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004899 }
Wink Saville36469e72014-06-11 15:17:00 -07004900 }
4901
Wink Saville36469e72014-06-11 15:17:00 -07004902 /**
4903 * {@hide}
4904 * Returns Default subId, 0 in the case of single standby.
4905 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004906 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004907 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004908 }
4909
Shishir Agrawala9f32182016-04-12 12:00:16 -07004910 private int getSlotForDefaultSubscription() {
4911 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4912 }
4913
Wink Savilleb564aae2014-10-23 10:18:09 -07004914 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004915 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004916 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004917
Pengquan Menge92a50d2018-09-21 15:54:48 -07004918 private boolean isActiveSubscription(int subId) {
4919 return mSubscriptionController.isActiveSubId(subId);
4920 }
4921
Ihab Awadf2177b72013-11-25 13:33:23 -08004922 /**
4923 * @see android.telephony.TelephonyManager.WifiCallingChoices
4924 */
4925 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004928 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4930 getWhenToMakeWifiCallsDefaultPreference());
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004934 }
4935
4936 /**
4937 * @see android.telephony.TelephonyManager.WifiCallingChoices
4938 */
4939 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004943 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004948 }
4949
Sailesh Nepald1e68152013-12-12 19:08:02 -08004950 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004951 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004952 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004953 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004954
Jordan Liu4c733742019-02-28 12:03:40 -08004955 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4956 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4957 if (phoneId == -1) {
4958 throw new IllegalArgumentException("Given slot index: " + slotIndex
4959 + " does not correspond to an active phone");
4960 }
4961 return PhoneFactory.getPhone(phoneId);
4962 }
4963
Shishir Agrawal566b7612013-10-28 14:41:00 -07004964 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004965 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4966 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4968 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004970 if (DBG) {
4971 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4972 }
4973 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4974 p2);
4975 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004976
Jordan Liu4c733742019-02-28 12:03:40 -08004977
4978 @Override
4979 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4980 int slotIndex, String callingPackage, String aid, int p2) {
4981 enforceModifyPermission();
4982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4983 if (DBG) {
4984 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4985 }
4986 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4987 callingPackage, aid, p2);
4988 }
4989
4990 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4991 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 if (TextUtils.equals(ISDR_AID, aid)) {
4995 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004996 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4997 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 if (bestComponent == null
4999 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5000 loge("The calling package is not allowed to access ISD-R.");
5001 throw new SecurityException(
5002 "The calling package is not allowed to access ISD-R.");
5003 }
Derek Tan740e1672017-06-27 14:56:27 -07005004 }
Derek Tan740e1672017-06-27 14:56:27 -07005005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005007 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5008 null /* workSource */);
5009 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 return response;
5011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005014 }
5015
5016 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005017 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5019 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005020 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5021 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005023
Jordan Liu4c733742019-02-28 12:03:40 -08005024 @Override
5025 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5026 enforceModifyPermission();
5027 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5028 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5029 channel);
5030 }
5031
5032 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 final long identity = Binder.clearCallingIdentity();
5034 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 if (channel < 0) {
5036 return false;
5037 }
Jordan Liu4c733742019-02-28 12:03:40 -08005038 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5039 null /* workSource */);
5040 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 return success;
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005044 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005045 }
5046
5047 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005048 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005049 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5051 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005052 if (DBG) {
5053 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5054 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5055 + p3 + " data=" + data);
5056 }
5057 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5058 command, p1, p2, p3, data);
5059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005060
Jordan Liu4c733742019-02-28 12:03:40 -08005061 @Override
5062 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5063 int command, int p1, int p2, int p3, String data) {
5064 enforceModifyPermission();
5065 if (DBG) {
5066 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5067 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5068 + p3 + " data=" + data);
5069 }
5070 return iccTransmitApduLogicalChannelWithPermission(
5071 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5072 data);
5073 }
5074
5075 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5076 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005079 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 return "";
5081 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005084 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5085 null /* workSource */);
5086 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 // Append the returned status code to the end of the response payload.
5089 String s = Integer.toHexString(
5090 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5091 if (response.payload != null) {
5092 s = IccUtils.bytesToHexString(response.payload) + s;
5093 }
5094 return s;
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005097 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005098 }
Jake Hambye994d462014-02-03 13:10:13 -08005099
Evan Charltonc66da362014-05-16 14:06:40 -07005100 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005101 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5102 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5104 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005106 if (DBG) {
5107 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5108 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5109 }
5110 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5111 cla, command, p1, p2, p3, data);
5112 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005113
Jordan Liu4c733742019-02-28 12:03:40 -08005114 @Override
5115 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5116 int command, int p1, int p2, int p3, String data) {
5117 enforceModifyPermission();
5118 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5119 if (DBG) {
5120 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5121 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5122 + " data=" + data);
5123 }
5124
5125 return iccTransmitApduBasicChannelWithPermission(
5126 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5127 p2, p3, data);
5128 }
5129
5130 // open APDU basic channel assuming the caller has sufficient permissions
5131 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5132 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5136 && TextUtils.equals(ISDR_AID, data)) {
5137 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005138 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5139 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 if (bestComponent == null
5141 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5142 loge("The calling package is not allowed to select ISD-R.");
5143 throw new SecurityException(
5144 "The calling package is not allowed to select ISD-R.");
5145 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005146 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005149 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5150 null /* workSource */);
5151 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 // Append the returned status code to the end of the response payload.
5154 String s = Integer.toHexString(
5155 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5156 if (response.payload != null) {
5157 s = IccUtils.bytesToHexString(response.payload) + s;
5158 }
5159 return s;
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005162 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005163 }
5164
5165 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005166 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005167 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5169 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 if (DBG) {
5174 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5175 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5176 }
5177
5178 IccIoResult response =
5179 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5180 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5181 subId);
5182
5183 if (DBG) {
5184 log("Exchange SIM_IO [R]" + response);
5185 }
5186
5187 byte[] result = null;
5188 int length = 2;
5189 if (response.payload != null) {
5190 length = 2 + response.payload.length;
5191 result = new byte[length];
5192 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5193 } else {
5194 result = new byte[length];
5195 }
5196
5197 result[length - 1] = (byte) response.sw2;
5198 result[length - 2] = (byte) response.sw1;
5199 return result;
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005202 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005203 }
5204
Nathan Haroldb3014052017-01-25 15:57:32 -08005205 /**
5206 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5207 * on a particular subscription
5208 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005209 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5210 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005212 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005213 return null;
5214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215
5216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 if (appType != TelephonyManager.APPTYPE_USIM
5219 && appType != TelephonyManager.APPTYPE_SIM) {
5220 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5221 return null;
5222 }
5223 Object response = sendRequest(
5224 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5225 if (response instanceof String[]) {
5226 return (String[]) response;
5227 }
yincheng zhao2737e882019-09-06 17:06:54 -07005228 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005230 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 } finally {
5232 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005233 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005234 }
5235
yincheng zhao2737e882019-09-06 17:06:54 -07005236 /**
5237 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5238 * subscription.
5239 *
5240 * @param subId the id of the subscription.
5241 * @param appType the uicc app type, must be USIM or SIM.
5242 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5243 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005244 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005245 * @return number of fplmns that is successfully written to the SIM.
5246 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005247 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5248 String callingFeatureId) {
5249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5250 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005251 if (DBG) logv("no permissions for setForbiddenplmns");
5252 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5253 }
5254 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5255 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5256 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5257 }
5258 if (fplmns == null) {
5259 throw new IllegalArgumentException("Fplmn List provided is null");
5260 }
5261 for (String fplmn : fplmns) {
5262 if (!CellIdentity.isValidPlmn(fplmn)) {
5263 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5264 }
5265 }
5266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 Object response = sendRequest(
5269 CMD_SET_FORBIDDEN_PLMNS,
5270 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5271 subId);
5272 return (int) response;
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
5276 }
5277
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005279 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5281 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5286 if (response.payload == null) {
5287 return "";
5288 }
Evan Charltonc66da362014-05-16 14:06:40 -07005289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 // Append the returned status code to the end of the response payload.
5291 String s = Integer.toHexString(
5292 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5293 s = IccUtils.bytesToHexString(response.payload) + s;
5294 return s;
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
Evan Charltonc66da362014-05-16 14:06:40 -07005298 }
5299
Jake Hambye994d462014-02-03 13:10:13 -08005300 /**
5301 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5302 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5303 *
5304 * @param itemID the ID of the item to read
5305 * @return the NV item as a String, or null on error.
5306 */
5307 @Override
5308 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005316 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5318 return value;
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
5321 }
Jake Hambye994d462014-02-03 13:10:13 -08005322 }
5323
5324 /**
5325 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5326 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5327 *
5328 * @param itemID the ID of the item to read
5329 * @param itemValue the value to write, as a String
5330 * @return true on success; false on any failure
5331 */
5332 @Override
5333 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5336 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337
5338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5341 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005342 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5344 return success;
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
Jake Hambye994d462014-02-03 13:10:13 -08005348 }
5349
5350 /**
5351 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5352 * Used for device configuration by some CDMA operators.
5353 *
5354 * @param preferredRoamingList byte array containing the new PRL
5355 * @return true on success; false on any failure
5356 */
5357 @Override
5358 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5360 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361
5362 final long identity = Binder.clearCallingIdentity();
5363 try {
5364 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5365 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5366 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5367 return success;
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
Jake Hambye994d462014-02-03 13:10:13 -08005371 }
5372
5373 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005374 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005375 * Used for device configuration by some CDMA operators.
5376 *
chen xu6dac5ab2018-10-26 17:39:23 -07005377 * @param slotIndex - device slot.
5378 *
Jake Hambye994d462014-02-03 13:10:13 -08005379 * @return true on success; false on any failure
5380 */
5381 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005382 public boolean resetModemConfig(int slotIndex) {
5383 Phone phone = PhoneFactory.getPhone(slotIndex);
5384 if (phone != null) {
5385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5386 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387
chen xu6dac5ab2018-10-26 17:39:23 -07005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5391 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5392 return success;
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 }
chen xu6dac5ab2018-10-26 17:39:23 -07005397 return false;
5398 }
5399
5400 /**
5401 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5402 *
5403 * @param slotIndex - device slot.
5404 *
5405 * @return true on success; false on any failure
5406 */
5407 @Override
5408 public boolean rebootModem(int slotIndex) {
5409 Phone phone = PhoneFactory.getPhone(slotIndex);
5410 if (phone != null) {
5411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5412 mApp, phone.getSubId(), "rebootModem");
5413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5417 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5418 return success;
5419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
5422 }
5423 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005425
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005426 public String[] getPcscfAddress(String apnType, String callingPackage,
5427 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005428 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5430 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005431 return new String[0];
5432 }
5433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 final long identity = Binder.clearCallingIdentity();
5435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005436 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
Wink Saville36469e72014-06-11 15:17:00 -07005440 }
5441
Brad Ebinger51f743a2017-01-23 13:50:20 -08005442 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005443 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5444 * {@link #disableIms(int)}.
5445 * @param slotIndex device slot.
5446 */
5447 public void resetIms(int slotIndex) {
5448 enforceModifyPermission();
5449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 if (mImsResolver == null) {
5453 // may happen if the does not support IMS.
5454 return;
5455 }
5456 mImsResolver.disableIms(slotIndex);
5457 mImsResolver.enableIms(slotIndex);
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
5461 }
5462
5463 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005464 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5465 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005466 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005467 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005472 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005473 // may happen if the device does not support IMS.
5474 return;
5475 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005476 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005480 }
5481
5482 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005483 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5484 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005485 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005486 public void disableIms(int slotId) {
5487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005491 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005492 // may happen if the device does not support IMS.
5493 return;
5494 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005495 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005499 }
5500
5501 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005502 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5503 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005504 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005505 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005506 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005511 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005512 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5513 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005514 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005515 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005519 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005520 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005521 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5522 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005523 @Override
5524 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005525 enforceModifyPermission();
5526
5527 final long identity = Binder.clearCallingIdentity();
5528 try {
5529 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005530 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
5534 }
5535
5536 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005537 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005538 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005539 */
5540 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542
5543 final long identity = Binder.clearCallingIdentity();
5544 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005545 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005546 // may happen if the device does not support IMS.
5547 return null;
5548 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005549 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005553 }
5554
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005555 /**
5556 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005557 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005558 */
5559 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005564 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005565 // may happen if the device does not support IMS.
5566 return null;
5567 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005568 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005572 }
5573
Brad Ebinger884c07b2018-02-15 16:17:40 -08005574 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005575 * Sets the ImsService Package Name that Telephony will bind to.
5576 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005577 * @param slotIndex the slot ID that the ImsService should bind for.
5578 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005579 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005580 * @param featureTypes An integer array of feature types associated with a packageName.
5581 * @param packageName The name of the package that the current configuration will be replaced
5582 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005583 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005584 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005585 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5586 int[] featureTypes, String packageName) {
5587 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5590 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005591 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 final long identity = Binder.clearCallingIdentity();
5594 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005595 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005596 // may happen if the device does not support IMS.
5597 return false;
5598 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005599 Map<Integer, String> featureConfig = new HashMap<>();
5600 for (int featureType : featureTypes) {
5601 featureConfig.put(featureType, packageName);
5602 }
5603 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5604 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005608 }
5609
5610 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005611 * Clears any carrier ImsService overrides for the slot index specified that were previously
5612 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5613 *
5614 * This should only be used for testing.
5615 *
5616 * @param slotIndex the slot ID that the ImsService should bind for.
5617 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5618 */
5619 @Override
5620 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5621 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5623 "clearCarrierImsServiceOverride");
5624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5625 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5626 "clearCarrierImsServiceOverride");
5627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (mImsResolver == null) {
5631 // may happen if the device does not support IMS.
5632 return false;
5633 }
5634 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
5638 }
5639
5640 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005641 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005642 *
5643 * @param slotId The slot that the ImsService is associated with.
5644 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5645 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005646 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005647 * @return the package name of the ImsService configuration.
5648 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005649 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5650 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005651 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005652 TelephonyPermissions
5653 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5654 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5655 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 final long identity = Binder.clearCallingIdentity();
5658 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005659 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005660 // may happen if the device does not support IMS.
5661 return "";
5662 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005663 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005664 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5665 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005669 }
5670
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005671 /**
5672 * Get the MmTelFeature state associated with the requested subscription id.
5673 * @param subId The subscription that the MmTelFeature is associated with.
5674 * @param callback A callback with an integer containing the
5675 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5676 */
5677 @Override
5678 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5679 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5680 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5682 "IMS not available on device.");
5683 }
5684 final long token = Binder.clearCallingIdentity();
5685 try {
5686 int slotId = getSlotIndex(subId);
5687 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5688 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5689 + subId + "'");
5690 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5691 }
5692 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5693 try {
5694 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5695 } catch (RemoteException e) {
5696 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5697 + "Ignore");
5698 }
5699 });
5700 } finally {
5701 Binder.restoreCallingIdentity(token);
5702 }
5703 }
5704
Daniel Brightbb5840b2021-01-12 15:48:18 -08005705 /**
5706 * Sets the ims registration state on all valid {@link Phone}s.
5707 */
5708 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710
5711 final long identity = Binder.clearCallingIdentity();
5712 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005713 // NOTE: Before S, this method only set the default phone.
5714 for (final Phone phone : PhoneFactory.getPhones()) {
5715 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5716 phone.setImsRegistrationState(registered);
5717 }
5718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
Wink Saville36469e72014-06-11 15:17:00 -07005722 }
5723
5724 /**
Stuart Scott54788802015-03-30 13:18:01 -07005725 * Set the network selection mode to automatic.
5726 *
5727 */
5728 @Override
5729 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5731 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
shilufc958392020-01-20 11:36:01 -08005735 if (!isActiveSubscription(subId)) {
5736 return;
5737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005739 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5740 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Stuart Scott54788802015-03-30 13:18:01 -07005744 }
5745
Jack Yud10cdd42020-09-28 20:28:01 -07005746 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005747 * Ask the radio to connect to the input network and change selection mode to manual.
5748 *
5749 * @param subId the id of the subscription.
5750 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5751 * the operator to attach to.
5752 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5753 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5754 * normal network selection next time.
5755 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005756 */
5757 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005758 public boolean setNetworkSelectionModeManual(
5759 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5761 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005762
5763 if (!isActiveSubscription(subId)) {
5764 return false;
5765 }
5766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 final long identity = Binder.clearCallingIdentity();
5768 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005769 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005771 if (DBG) {
5772 log("setNetworkSelectionModeManual: subId: " + subId
5773 + " operator: " + operatorInfo);
5774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005779 }
shilu84f6e8b2019-12-19 13:58:01 -08005780 /**
5781 * Get the manual network selection
5782 *
5783 * @param subId the id of the subscription.
5784 *
5785 * @return the previously saved user selected PLMN
5786 */
5787 @Override
5788 public String getManualNetworkSelectionPlmn(int subId) {
5789 TelephonyPermissions
5790 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5791 mApp, subId, "getManualNetworkSelectionPlmn");
5792
5793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005796 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005797 }
5798
5799 final Phone phone = getPhone(subId);
5800 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005801 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005802 }
5803 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5804 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5805 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
5809 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005810
5811 /**
5812 * Scans for available networks.
5813 */
5814 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005815 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5816 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5818 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005819 LocationAccessPolicy.LocationPermissionResult locationResult =
5820 LocationAccessPolicy.checkLocationPermission(mApp,
5821 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5822 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005823 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005824 .setCallingPid(Binder.getCallingPid())
5825 .setCallingUid(Binder.getCallingUid())
5826 .setMethod("getCellNetworkScanResults")
5827 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005828 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5829 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005830 .build());
5831 switch (locationResult) {
5832 case DENIED_HARD:
5833 throw new SecurityException("Not allowed to access scan results -- location");
5834 case DENIED_SOFT:
5835 return null;
5836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837
Pengquan Menga1bb6272018-09-06 09:59:22 -07005838 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 try {
5840 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005841 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005846 }
5847
5848 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005849 * Get the call forwarding info, given the call forwarding reason.
5850 */
5851 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005852 public void getCallForwarding(int subId, int callForwardingReason,
5853 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005854 enforceReadPrivilegedPermission("getCallForwarding");
5855 long identity = Binder.clearCallingIdentity();
5856 try {
5857 if (DBG) {
5858 log("getCallForwarding: subId " + subId
5859 + " callForwardingReason" + callForwardingReason);
5860 }
Hall Liu27d24262020-09-18 19:04:59 -07005861
5862 Phone phone = getPhone(subId);
5863 if (phone == null) {
5864 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005865 callback.onError(
5866 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005867 } catch (RemoteException e) {
5868 // ignore
5869 }
5870 return;
5871 }
5872
5873 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5874 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5875 @Override
5876 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5877 try {
5878 callback.onCallForwardingInfoAvailable(info);
5879 } catch (RemoteException e) {
5880 // ignore
5881 }
5882 }
5883
5884 @Override
5885 public void onError(int error) {
5886 try {
5887 callback.onError(error);
5888 } catch (RemoteException e) {
5889 // ignore
5890 }
5891 }
5892 });
5893 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
5897 }
5898
5899 /**
5900 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5901 * reason, the number to forward, and the timeout before the forwarding is attempted.
5902 */
5903 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005904 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5905 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005906 enforceModifyPermission();
5907 long identity = Binder.clearCallingIdentity();
5908 try {
5909 if (DBG) {
5910 log("setCallForwarding: subId " + subId
5911 + " callForwardingInfo" + callForwardingInfo);
5912 }
Hall Liu27d24262020-09-18 19:04:59 -07005913
5914 Phone phone = getPhone(subId);
5915 if (phone == null) {
5916 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005917 callback.accept(
5918 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005919 } catch (RemoteException e) {
5920 // ignore
5921 }
5922 return;
5923 }
5924
5925 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5926 FunctionalUtils.ignoreRemoteException(callback::accept));
5927
5928 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
5932 }
5933
5934 /**
Hall Liu27d24262020-09-18 19:04:59 -07005935 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005936 */
5937 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005938 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005939 enforceReadPrivilegedPermission("getCallForwarding");
5940 long identity = Binder.clearCallingIdentity();
5941 try {
Hall Liu27d24262020-09-18 19:04:59 -07005942
5943 Phone phone = getPhone(subId);
5944 if (phone == null) {
5945 try {
5946 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5947 } catch (RemoteException e) {
5948 // ignore
5949 }
5950 return;
5951 }
5952
5953 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5954
Shuo Qian4a594052020-01-23 11:59:30 -08005955 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005956 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
5960 }
5961
5962 /**
Hall Liu27d24262020-09-18 19:04:59 -07005963 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005964 */
5965 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005966 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005967 enforceModifyPermission();
5968 long identity = Binder.clearCallingIdentity();
5969 try {
Hall Liu27d24262020-09-18 19:04:59 -07005970 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5971
5972 Phone phone = getPhone(subId);
5973 if (phone == null) {
5974 try {
5975 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5976 } catch (RemoteException e) {
5977 // ignore
5978 }
5979 return;
5980 }
5981
5982 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5983 FunctionalUtils.ignoreRemoteException(callback::accept));
5984
5985 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
5989 }
5990
5991 /**
yinxub1bed742017-04-17 11:45:04 -07005992 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005993 *
yinxub1bed742017-04-17 11:45:04 -07005994 * @param subId id of the subscription
5995 * @param request contains the radio access networks with bands/channels to scan
5996 * @param messenger callback messenger for scan results or errors
5997 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005998 * @return the id of the requested scan which can be used to stop the scan.
5999 */
6000 @Override
6001 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006002 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006005 LocationAccessPolicy.LocationPermissionResult locationResult =
6006 LocationAccessPolicy.checkLocationPermission(mApp,
6007 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6008 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006009 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006010 .setCallingPid(Binder.getCallingPid())
6011 .setCallingUid(Binder.getCallingUid())
6012 .setMethod("requestNetworkScan")
6013 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006014 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6015 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006016 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006017 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006018 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6019 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006020 if (e != null) {
6021 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6022 throw e;
6023 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006024 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006025 return TelephonyScanManager.INVALID_SCAN_ID;
6026 }
6027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 }
Hall Liu912dfd32019-04-25 14:02:26 -07006029 int callingUid = Binder.getCallingUid();
6030 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006031 final long identity = Binder.clearCallingIdentity();
6032 try {
6033 return mNetworkScanRequestTracker.startNetworkScan(
6034 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006035 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
yinxu504e1392017-04-12 16:03:22 -07006039 }
6040
Hall Liub2ac8ef2019-02-28 15:56:23 -08006041 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006042 NetworkScanRequest request, int subId, String callingPackage) {
6043 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006044 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6045 boolean hasNetworkScanPermission =
6046 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6047 == PERMISSION_GRANTED;
6048
6049 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6050 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6051 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006052 }
6053
6054 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6055 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006056 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6057 return new SecurityException("Specific channels must not be"
6058 + " scanned without location access.");
6059 }
6060 }
6061 }
6062
Hall Liub2ac8ef2019-02-28 15:56:23 -08006063 return null;
6064 }
6065
yinxu504e1392017-04-12 16:03:22 -07006066 /**
6067 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006068 *
6069 * @param subId id of the subscription
6070 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006071 */
6072 @Override
6073 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6075 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076
Hall Liu912dfd32019-04-25 14:02:26 -07006077 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 final long identity = Binder.clearCallingIdentity();
6079 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006080 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
yinxu504e1392017-04-12 16:03:22 -07006084 }
6085
6086 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006087 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006088 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006089 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006090 */
6091 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006092 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006093 TelephonyPermissions
6094 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006095 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096
6097 final long identity = Binder.clearCallingIdentity();
6098 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006099 if (DBG) log("getAllowedNetworkTypesBitmask");
6100 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6101 int networkTypesBitmask = (result != null ? result[0] : -1);
6102 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6103 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006107 }
6108
6109 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006110 * Get the allowed network types for certain reason.
6111 *
6112 * @param subId the id of the subscription.
6113 * @param reason the reason the allowed network type change is taking place
6114 * @return the allowed network types.
6115 */
6116 @Override
6117 public long getAllowedNetworkTypesForReason(int subId,
6118 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6119 TelephonyPermissions
6120 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6121 mApp, subId, "getAllowedNetworkTypesForReason");
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
6128 }
6129
6130 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006131 * Enable/Disable E-UTRA-NR Dual Connectivity
6132 * @param subId subscription id of the sim card
6133 * @param nrDualConnectivityState expected NR dual connectivity state
6134 * This can be passed following states
6135 * <ol>
6136 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6137 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6138 * <li>Disable NR dual connectivity and force secondary cell to be released
6139 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6140 * </ol>
6141 * @return operation result.
6142 */
6143 @Override
6144 public int setNrDualConnectivityState(int subId,
6145 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6147 mApp, subId, "enableNRDualConnectivity");
6148 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6152 nrDualConnectivityState, subId,
6153 workSource);
6154 if (DBG) log("enableNRDualConnectivity result: " + result);
6155 return result;
6156 } finally {
6157 Binder.restoreCallingIdentity(identity);
6158 }
6159 }
6160
6161 /**
6162 * Is E-UTRA-NR Dual Connectivity enabled
6163 * @return true if dual connectivity is enabled else false
6164 */
6165 @Override
6166 public boolean isNrDualConnectivityEnabled(int subId) {
6167 TelephonyPermissions
6168 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6169 mApp, subId, "isNRDualConnectivityEnabled");
6170 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6174 null, subId, workSource);
6175 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6176 return isEnabled;
6177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
6180 }
6181
6182 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006183 * get carrier bandwidth per primary and secondary carrier
6184 * @param subId subscription id of the sim card
6185 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6186 */
6187 @Override
6188 public CarrierBandwidth getCarrierBandwidth(int subId) {
6189 TelephonyPermissions
6190 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6191 mApp, subId, "isNRDualConnectivityEnabled");
6192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 CarrierBandwidth carrierBandwidth =
6196 getPhoneFromSubId(subId).getCarrierBandwidth();
6197 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6198 return carrierBandwidth;
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
6202 }
6203
6204 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006205 * Set the allowed network types of the device and
6206 * provide the reason triggering the allowed network change.
6207 *
6208 * @param subId the id of the subscription.
6209 * @param reason the reason the allowed network type change is taking place
6210 * @param allowedNetworkTypes the allowed network types.
6211 * @return true on success; false on any failure.
6212 */
6213 @Override
6214 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006215 @TelephonyManager.AllowedNetworkTypesReason int reason,
6216 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6218 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006219 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6220 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6221 return false;
6222 }
6223
6224 if (DBG) {
6225 log("setAllowedNetworkTypesForReason: " + reason
6226 + " value: " + allowedNetworkTypes);
6227 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006228 final long identity = Binder.clearCallingIdentity();
6229 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006230 Boolean success = (Boolean) sendRequest(
6231 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6232 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6233
6234 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6235 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
6239 }
6240
6241 /**
Miaoa84611c2019-03-15 09:21:10 +08006242 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006243 *
Miaoa84611c2019-03-15 09:21:10 +08006244 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006245 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006246 * @hide
6247 */
6248 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006249 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006252 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 try {
Miaoa84611c2019-03-15 09:21:10 +08006254 if (phone != null) {
6255 return phone.hasMatchedTetherApnSetting();
6256 } else {
6257 return false;
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006261 }
Junda Liu475951f2014-11-07 16:45:03 -08006262 }
6263
6264 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006265 * Enable or disable always reporting signal strength changes from radio.
6266 *
6267 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6268 */
6269 @Override
6270 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6271 enforceModifyPermission();
6272 enforceSystemCaller();
6273
6274 final long identity = Binder.clearCallingIdentity();
6275 final Phone phone = getPhone(subId);
6276 try {
6277 if (phone != null) {
6278 if (DBG) {
6279 log("setAlwaysReportSignalStrength: subId=" + subId
6280 + " isEnable=" + isEnable);
6281 }
6282 phone.setAlwaysReportSignalStrength(isEnable);
6283 } else {
6284 loge("setAlwaysReportSignalStrength: no phone found for subId="
6285 + subId);
6286 }
6287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
6290 }
6291
6292 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006293 * Get the user enabled state of Mobile Data.
6294 *
6295 * TODO: remove and use isUserDataEnabled.
6296 * This can't be removed now because some vendor codes
6297 * calls through ITelephony directly while they should
6298 * use TelephonyManager.
6299 *
6300 * @return true on enabled
6301 */
6302 @Override
6303 public boolean getDataEnabled(int subId) {
6304 return isUserDataEnabled(subId);
6305 }
6306
6307 /**
6308 * Get whether mobile data is enabled per user setting.
6309 *
6310 * There are other factors deciding whether mobile data is actually enabled, but they are
6311 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006312 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006313 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006314 *
6315 * @return {@code true} if data is enabled else {@code false}
6316 */
6317 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006318 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006319 try {
6320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6321 null);
6322 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 int phoneId = mSubscriptionController.getPhoneId(subId);
6330 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6331 Phone phone = PhoneFactory.getPhone(phoneId);
6332 if (phone != null) {
6333 boolean retVal = phone.isUserDataEnabled();
6334 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6335 return retVal;
6336 } else {
6337 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6338 return false;
6339 }
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006342 }
6343 }
6344
6345 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006346 * Checks if the device is capable of mobile data by considering whether whether the
6347 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6348 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006349 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006350 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006351 */
6352 @Override
6353 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006354 try {
6355 try {
6356 mApp.enforceCallingOrSelfPermission(
6357 android.Manifest.permission.ACCESS_NETWORK_STATE,
6358 null);
6359 } catch (Exception e) {
6360 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6361 "isDataEnabled");
6362 }
6363 } catch (Exception e) {
6364 enforceReadPrivilegedPermission("isDataEnabled");
6365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366
6367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 int phoneId = mSubscriptionController.getPhoneId(subId);
6370 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6371 Phone phone = PhoneFactory.getPhone(phoneId);
6372 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006373 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6375 return retVal;
6376 } else {
6377 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6378 return false;
6379 }
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006382 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006383 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006384
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006385 /**
6386 * Check if data is enabled for a specific reason
6387 * @param subId Subscription index
6388 * @param reason the reason the data enable change is taking place
6389 * @return {@code true} if the overall data is enabled; {@code false} if not.
6390 */
6391 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006392 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006393 @TelephonyManager.DataEnabledReason int reason) {
6394 try {
6395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6396 null);
6397 } catch (Exception e) {
6398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006399 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006400 }
6401
6402
6403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 int phoneId = mSubscriptionController.getPhoneId(subId);
6406 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006407 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006408 + " reason=" + reason);
6409 }
6410 Phone phone = PhoneFactory.getPhone(phoneId);
6411 if (phone != null) {
6412 boolean retVal;
6413 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6414 retVal = phone.isUserDataEnabled();
6415 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006416 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006417 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006418 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006419 return retVal;
6420 } else {
6421 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006422 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006423 + subId + " retVal=false");
6424 }
6425 return false;
6426 }
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006432 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006433 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006434 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6435 // Skip the check if it's one of these special uids
6436 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6437 }
6438
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006439 //load access rules from carrier configs, and check those as well: b/139133814
6440 SubscriptionController subController = SubscriptionController.getInstance();
6441 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6442 || subController == null) return privilegeFromSim;
6443
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006444 PackageManager pkgMgr = phone.getContext().getPackageManager();
6445 String[] packages = pkgMgr.getPackagesForUid(uid);
6446
6447 final long identity = Binder.clearCallingIdentity();
6448 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006449 int subId = phone.getSubId();
6450 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6451 // A test override is in place for the privileges for this subId, so don't try to
6452 // read the subscription privileges.
6453 return privilegeFromSim;
6454 }
6455 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006456 SubscriptionManager subManager = (SubscriptionManager)
6457 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6458 for (String pkg : packages) {
6459 if (subManager.canManageSubscription(subInfo, pkg)) {
6460 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6461 }
6462 }
6463 return privilegeFromSim;
6464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
6467 }
6468
6469 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6470 String pkgName) {
6471 //load access rules from carrier configs, and check those as well: b/139133814
6472 SubscriptionController subController = SubscriptionController.getInstance();
6473 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6474 || subController == null) return privilegeFromSim;
6475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006478 int subId = phone.getSubId();
6479 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6480 // A test override is in place for the privileges for this subId, so don't try to
6481 // read the subscription privileges.
6482 return privilegeFromSim;
6483 }
6484 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006485 SubscriptionManager subManager = (SubscriptionManager)
6486 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6487 return subManager.canManageSubscription(subInfo, pkgName)
6488 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
6492 }
6493
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006494 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006495 public int getCarrierPrivilegeStatus(int subId) {
6496 final Phone phone = getPhone(subId);
6497 if (phone == null) {
6498 loge("getCarrierPrivilegeStatus: Invalid subId");
6499 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6500 }
6501 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006502 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006503 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006504 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6505 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006506
6507 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6508 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006509 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006510 }
Junda Liu29340342014-07-10 15:23:27 -07006511
6512 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006513 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006514 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006515 final Phone phone = getPhone(subId);
6516 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006517 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006518 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6519 }
6520 UiccProfile profile =
6521 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6522 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006523 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6525 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006526 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006527 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006528 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006529 }
6530
6531 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006532 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6533 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006534 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006535 }
6536
6537 int phoneId = SubscriptionManager.getPhoneId(subId);
6538 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006539 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006540 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6542 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006543 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6544 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6545 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006546 }
6547
6548 @Override
6549 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006550 if (TextUtils.isEmpty(pkgName))
6551 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006552 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6553 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6554 UiccCard card = UiccController.getInstance().getUiccCard(i);
6555 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006556 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006557 continue;
6558 }
6559
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006560 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6561 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6562 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006563 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6564 break;
6565 }
6566 }
6567
6568 return result;
Junda Liu29340342014-07-10 15:23:27 -07006569 }
Derek Tan89e89d42014-07-08 17:00:10 -07006570
6571 @Override
Junda Liue64de782015-04-16 17:19:16 -07006572 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6573 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6574 loge("phoneId " + phoneId + " is not valid.");
6575 return null;
6576 }
6577 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006578 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006579 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006580 return null ;
6581 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006582 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006583 }
6584
Amith Yamasani6e118872016-02-19 12:53:51 -08006585 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006586 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006587 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006588 List<String> privilegedPackages = new ArrayList<>();
6589 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006590 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6591 // has UICC in that slot.
6592 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006593 if (card.hasCarrierPrivilegeRules()) {
6594 if (packages == null) {
6595 // Only check packages in user 0 for now
6596 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006597 PackageManager.MATCH_DISABLED_COMPONENTS
6598 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006599 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006600 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006601 }
6602 for (int p = packages.size() - 1; p >= 0; p--) {
6603 PackageInfo pkgInfo = packages.get(p);
6604 if (pkgInfo != null && pkgInfo.packageName != null
6605 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006606 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006607 privilegedPackages.add(pkgInfo.packageName);
6608 }
6609 }
6610 }
6611 }
6612 return privilegedPackages;
6613 }
6614
chen xuf7e9fe82019-05-09 19:31:02 -07006615 @Override
6616 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006617 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6618
6619 final long identity = Binder.clearCallingIdentity();
6620
chen xuf7e9fe82019-05-09 19:31:02 -07006621 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006622 try {
6623 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6624 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6625 }
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006628 }
6629 return privilegedPackages;
6630 }
6631
Wink Savilleb564aae2014-10-23 10:18:09 -07006632 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006633 final Phone phone = getPhone(subId);
6634 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006635 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006636 return null;
6637 }
6638 String iccId = card.getIccId();
6639 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006640 return null;
6641 }
6642 return iccId;
6643 }
6644
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006645 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006646 public void setCallComposerStatus(int subId, int status) {
6647 enforceModifyPermission();
6648
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 Phone phone = getPhone(subId);
6652 if (phone != null) {
6653 Phone defaultPhone = phone.getImsPhone();
6654 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6655 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6656 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006657 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6658 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006659 }
6660 }
Shuo Qian284ae752020-12-22 19:10:14 -08006661 } catch (ImsException e) {
6662 throw new ServiceSpecificException(e.getCode());
6663 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006664 Binder.restoreCallingIdentity(identity);
6665 }
6666 }
6667
6668 @Override
6669 public int getCallComposerStatus(int subId) {
6670 enforceReadPrivilegedPermission("getCallComposerStatus");
6671
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 Phone phone = getPhone(subId);
6675 if (phone != null) {
6676 Phone defaultPhone = phone.getImsPhone();
6677 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6678 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6679 return imsPhone.getCallComposerStatus();
6680 }
6681 }
6682 } finally {
6683 Binder.restoreCallingIdentity(identity);
6684 }
6685 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6686 }
6687
6688 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006689 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6690 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006692 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 final String iccId = getIccId(subId);
6697 final Phone phone = getPhone(subId);
6698 if (phone == null) {
6699 return false;
6700 }
6701 final String subscriberId = phone.getSubscriberId();
6702
6703 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006704 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 + subscriberId + " to " + number);
6706 }
6707
6708 if (TextUtils.isEmpty(iccId)) {
6709 return false;
6710 }
6711
6712 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6713
6714 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6715 if (alphaTag == null) {
6716 editor.remove(alphaTagPrefKey);
6717 } else {
6718 editor.putString(alphaTagPrefKey, alphaTag);
6719 }
6720
6721 // Record both the line number and IMSI for this ICCID, since we need to
6722 // track all merged IMSIs based on line number
6723 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6724 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6725 if (number == null) {
6726 editor.remove(numberPrefKey);
6727 editor.remove(subscriberPrefKey);
6728 } else {
6729 editor.putString(numberPrefKey, number);
6730 editor.putString(subscriberPrefKey, subscriberId);
6731 }
6732
6733 editor.commit();
6734 return true;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006737 }
Derek Tan7226c842014-07-02 17:42:23 -07006738 }
6739
6740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006741 public String getLine1NumberForDisplay(int subId, String callingPackage,
6742 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006743 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006745 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006746 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006747 return null;
6748 }
Derek Tan97ebb422014-09-05 16:55:38 -07006749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 final long identity = Binder.clearCallingIdentity();
6751 try {
6752 String iccId = getIccId(subId);
6753 if (iccId != null) {
6754 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6755 if (DBG_MERGE) {
6756 log("getLine1NumberForDisplay returning "
6757 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6758 }
6759 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6762 return null;
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006765 }
Derek Tan7226c842014-07-02 17:42:23 -07006766 }
6767
6768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006769 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6770 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006772 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006773 return null;
6774 }
Derek Tan97ebb422014-09-05 16:55:38 -07006775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 final long identity = Binder.clearCallingIdentity();
6777 try {
6778 String iccId = getIccId(subId);
6779 if (iccId != null) {
6780 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6781 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6782 }
6783 return null;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006786 }
Derek Tan7226c842014-07-02 17:42:23 -07006787 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006788
6789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6791 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006792 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6793 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006795 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006796 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006797 return null;
6798 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006799
Jordan Liub49b04b2019-05-06 14:45:15 -07006800 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6801 // the process, where TelephonyManager was instantiated.
6802 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006803 final long identity = Binder.clearCallingIdentity();
6804 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006805 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 final TelephonyManager tele = TelephonyManager.from(context);
6807 final SubscriptionManager sub = SubscriptionManager.from(context);
6808
6809 // Figure out what subscribers are currently active
6810 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811
Jordan Liub49b04b2019-05-06 14:45:15 -07006812 // Only consider subs which match the current subId
6813 // This logic can be simplified. See b/131189269 for progress.
6814 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006815 activeSubscriberIds.add(tele.getSubscriberId(subId));
6816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817
6818 // First pass, find a number override for an active subscriber
6819 String mergeNumber = null;
6820 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6821 for (String key : prefs.keySet()) {
6822 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6823 final String subscriberId = (String) prefs.get(key);
6824 if (activeSubscriberIds.contains(subscriberId)) {
6825 final String iccId = key.substring(
6826 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6827 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6828 mergeNumber = (String) prefs.get(numberKey);
6829 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006830 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 + " for active subscriber " + subscriberId);
6832 }
6833 if (!TextUtils.isEmpty(mergeNumber)) {
6834 break;
6835 }
6836 }
6837 }
6838 }
6839
6840 // Shortcut when no active merged subscribers
6841 if (TextUtils.isEmpty(mergeNumber)) {
6842 return null;
6843 }
6844
6845 // Second pass, find all subscribers under that line override
6846 final ArraySet<String> result = new ArraySet<>();
6847 for (String key : prefs.keySet()) {
6848 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6849 final String number = (String) prefs.get(key);
6850 if (mergeNumber.equals(number)) {
6851 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6852 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6853 final String subscriberId = (String) prefs.get(subscriberKey);
6854 if (!TextUtils.isEmpty(subscriberId)) {
6855 result.add(subscriberId);
6856 }
6857 }
6858 }
6859 }
6860
6861 final String[] resultArray = result.toArray(new String[result.size()]);
6862 Arrays.sort(resultArray);
6863 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006864 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6866 }
6867 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006868 } finally {
6869 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006870 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006871 }
6872
6873 @Override
zoey chen38003472019-12-13 17:16:31 +08006874 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6875 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 final TelephonyManager telephonyManager = mApp.getSystemService(
6880 TelephonyManager.class);
6881 String subscriberId = telephonyManager.getSubscriberId(subId);
6882 if (subscriberId == null) {
6883 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006884 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006885 + subId);
6886 }
6887 return null;
6888 }
6889
6890 final SubscriptionInfo info = SubscriptionController.getInstance()
6891 .getSubscriptionInfo(subId);
6892 final ParcelUuid groupUuid = info.getGroupUuid();
6893 // If it doesn't belong to any group, return just subscriberId of itself.
6894 if (groupUuid == null) {
6895 return new String[]{subscriberId};
6896 }
6897
6898 // Get all subscriberIds from the group.
6899 final List<String> mergedSubscriberIds = new ArrayList<>();
6900 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006901 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006902 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006903 for (SubscriptionInfo subInfo : groupInfos) {
6904 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6905 if (subscriberId != null) {
6906 mergedSubscriberIds.add(subscriberId);
6907 }
6908 }
6909
6910 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6911 } finally {
6912 Binder.restoreCallingIdentity(identity);
6913
6914 }
6915 }
6916
6917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006918 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006919 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006920 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 final Phone phone = getPhone(subId);
6925 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
6928 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006929 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006930
6931 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006932 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006933 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6934 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006935 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6936 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937
6938 final long identity = Binder.clearCallingIdentity();
6939 try {
6940 final Phone phone = getPhone(subId);
6941 if (phone == null) {
6942 return false;
6943 }
6944 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6945 cdmaNonRoamingList);
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006948 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006949 }
6950
6951 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006952 @Deprecated
6953 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6954 enforceModifyPermission();
6955
6956 int returnValue = 0;
6957 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006958 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006959 if(result.exception == null) {
6960 if (result.result != null) {
6961 byte[] responseData = (byte[])(result.result);
6962 if(responseData.length > oemResp.length) {
6963 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6964 responseData.length + "bytes. Buffer Size is " +
6965 oemResp.length + "bytes.");
6966 }
6967 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6968 returnValue = responseData.length;
6969 }
6970 } else {
6971 CommandException ex = (CommandException) result.exception;
6972 returnValue = ex.getCommandError().ordinal();
6973 if(returnValue > 0) returnValue *= -1;
6974 }
6975 } catch (RuntimeException e) {
6976 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6977 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6978 if(returnValue > 0) returnValue *= -1;
6979 }
6980
6981 return returnValue;
6982 }
6983
6984 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006985 public void setRadioCapability(RadioAccessFamily[] rafs) {
6986 try {
6987 ProxyController.getInstance().setRadioCapability(rafs);
6988 } catch (RuntimeException e) {
6989 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6990 }
6991 }
6992
6993 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006994 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006995 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006996 try {
6997 TelephonyPermissions
6998 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6999 mApp, phone.getSubId(), "getRadioAccessFamily");
7000 } catch (SecurityException e) {
7001 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7002 throw e;
7003 }
chen xub97461a2018-10-26 14:17:57 -07007004 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007005 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007006 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final long identity = Binder.clearCallingIdentity();
7009 try {
chen xub97461a2018-10-26 14:17:57 -07007010 TelephonyPermissions
7011 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7012 mApp, phone.getSubId(), "getRadioAccessFamily");
7013 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
chen xub97461a2018-10-26 14:17:57 -07007017 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007018 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007019
7020 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007021 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007022 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007023 try {
7024 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7025 Binder.getCallingUid())) {
7026 throw new SecurityException("Package uid and package name do not match: "
7027 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7028 }
7029 } catch (PackageManager.NameNotFoundException e) {
7030 throw new SecurityException("Package name invalid:" + callingPackage);
7031 }
7032 RoleManager rm = mApp.getSystemService(RoleManager.class);
7033 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7034 if (!dialerRoleHolders.contains(callingPackage)) {
7035 throw new SecurityException("App must be the dialer role holder to"
7036 + " upload a call composer pic");
7037 }
7038
7039 Executors.newSingleThreadExecutor().execute(() -> {
7040 ByteArrayOutputStream output = new ByteArrayOutputStream(
7041 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7042 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7043 boolean readUntilEnd = false;
7044 int totalBytesRead = 0;
7045 byte[] buffer = new byte[16 * 1024];
7046 while (true) {
7047 int numRead;
7048 try {
7049 numRead = input.read(buffer);
7050 } catch (IOException e) {
7051 try {
7052 fd.checkError();
7053 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7054 null);
7055 } catch (IOException e1) {
7056 // This means that the other side closed explicitly with an error. If this
7057 // happens, log and ignore.
7058 loge("Remote end of call composer picture pipe closed: " + e1);
7059 }
7060 break;
7061 }
7062 if (numRead == -1) {
7063 readUntilEnd = true;
7064 break;
7065 }
7066 totalBytesRead += numRead;
7067 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7068 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7069 try {
7070 input.close();
7071 } catch (IOException e) {
7072 // ignore
7073 }
7074 break;
7075 }
7076 output.write(buffer, 0, numRead);
7077 }
7078 // Generally, the remote end will close the file descriptors. The only case where we
7079 // close is above, where the picture size is too big.
7080
7081 try {
7082 fd.checkError();
7083 } catch (IOException e) {
7084 loge("Remote end for call composer closed with an error: " + e);
7085 return;
7086 }
7087
Hall Liuaa4211e2021-01-20 15:43:39 -08007088 if (!readUntilEnd) {
7089 loge("Did not finish reading entire image; aborting");
7090 return;
7091 }
Hall Liu82694d52020-12-11 18:22:04 -08007092
Hall Liuaa4211e2021-01-20 15:43:39 -08007093 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7094 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7095 new CallComposerPictureTransfer.Factory() {},
7096 imageData,
7097 (result) -> {
7098 if (result.first != null) {
7099 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7100 Bundle outputResult = new Bundle();
7101 outputResult.putParcelable(
7102 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7103 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7104 outputResult);
7105 } else {
7106 callback.send(result.second, null);
7107 }
7108 }
7109 );
Hall Liu82694d52020-12-11 18:22:04 -08007110 });
7111 }
7112
7113 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007114 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007115 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117
7118 final long identity = Binder.clearCallingIdentity();
7119 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 ImsManager.getInstance(defaultPhone.getContext(),
7121 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007125 }
7126
7127 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007128 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007129 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7131 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007132 return false;
7133 }
Svet Ganovb320e182015-04-16 12:30:10 -07007134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 // Check the user preference and the system-level IMS setting. Even if the user has
7138 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7139 // In the long run, we may instead need to check if there exists a connection service
7140 // which can support video calling.
7141 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007142 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 return imsManager.isVtEnabledByPlatform()
7144 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7145 && imsManager.isVtEnabledByUser();
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007149 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007150
Andrew Leea1239f22015-03-02 17:44:07 -08007151 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007152 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7153 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007155 mApp, subId, callingPackage, callingFeatureId,
7156 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 return false;
7158 }
7159
7160 final long identity = Binder.clearCallingIdentity();
7161 try {
7162 CarrierConfigManager configManager =
7163 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007164 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007165 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7166 } finally {
7167 Binder.restoreCallingIdentity(identity);
7168 }
Andrew Leea1239f22015-03-02 17:44:07 -08007169 }
7170
7171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007172 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 return false;
7176 }
7177
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 CarrierConfigManager configManager =
7181 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007182 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
Andrew Leea1239f22015-03-02 17:44:07 -08007187 }
7188
Andrew Lee9431b832015-03-09 18:46:45 -07007189 @Override
7190 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007191 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007192 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007193 }
7194
7195 @Override
7196 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007199 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 } finally {
7201 Binder.restoreCallingIdentity(identity);
7202 }
Andrew Lee9431b832015-03-09 18:46:45 -07007203 }
7204
Hall Liuf6668912018-10-31 17:05:23 -07007205 /**
7206 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7207 * support for the feature and device firmware support.
7208 *
7209 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7210 */
7211 @Override
7212 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007214 final Phone phone = getPhone(subscriptionId);
7215 if (phone == null) {
7216 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7217 return false;
7218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007220 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7222 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007223 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 return isCarrierSupported && isDeviceSupported;
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
Hall Liu98187582018-01-22 19:15:32 -08007228 }
7229
Hall Liuf6668912018-10-31 17:05:23 -07007230 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007231 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7232 * RTT setting, will return true if the device and carrier both support RTT.
7233 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007234 */
7235 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 final long identity = Binder.clearCallingIdentity();
7237 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007238 boolean isRttSupported = isRttSupported(subscriptionId);
7239 boolean isUserRttSettingOn = Settings.Secure.getInt(
7240 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7241 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7242 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7243 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007247 }
7248
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007249 @Deprecated
7250 @Override
7251 public String getDeviceId(String callingPackage) {
7252 return getDeviceIdWithFeature(callingPackage, null);
7253 }
7254
Sanket Padawe7310cc72015-01-14 09:53:20 -08007255 /**
7256 * Returns the unique device ID of phone, for example, the IMEI for
7257 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7258 *
7259 * <p>Requires Permission:
7260 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7261 */
7262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007263 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007264 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007265 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007266 return null;
7267 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007268 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007269 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007270 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 return null;
7272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 return phone.getDeviceId();
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007280 }
7281
Ping Sunc67b7c22016-03-02 19:16:45 +08007282 /**
7283 * {@hide}
7284 * Returns the IMS Registration Status on a particular subid
7285 *
7286 * @param subId
7287 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007288 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007289 Phone phone = getPhone(subId);
7290 if (phone != null) {
7291 return phone.isImsRegistered();
7292 } else {
7293 return false;
7294 }
7295 }
7296
Santos Cordon7a1885b2015-02-03 11:15:19 -08007297 @Override
7298 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007305 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007306
Tyler Gunnf70ed162019-04-03 15:28:53 -07007307 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007308 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007309 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007311 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007312 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7313 }
7314 final long identity = Binder.clearCallingIdentity();
7315 try {
7316 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
7320 }
7321
7322 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007323 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007324 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7325 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 Phone phone = getPhone(subscriptionId);
7329 if (phone == null) {
7330 return null;
7331 }
7332 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
7336 }
7337
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007338 /**
7339 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007340 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007341 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 Phone phone = getPhone(subId);
7345 if (phone != null) {
7346 return phone.isWifiCallingEnabled();
7347 } else {
7348 return false;
7349 }
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007352 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007353 }
7354
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007355 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007356 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007357 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007358 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 final long identity = Binder.clearCallingIdentity();
7360 try {
7361 Phone phone = getPhone(subId);
7362 if (phone != null) {
7363 return phone.isVideoEnabled();
7364 } else {
7365 return false;
7366 }
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007369 }
7370 }
7371
7372 /**
7373 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7374 * defined in {@link ImsRegistrationImplBase}.
7375 */
7376 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final long identity = Binder.clearCallingIdentity();
7378 try {
7379 Phone phone = getPhone(subId);
7380 if (phone != null) {
7381 return phone.getImsRegistrationTech();
7382 } else {
7383 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7384 }
7385 } finally {
7386 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007387 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007388 }
7389
Stuart Scott8eef64f2015-04-08 15:13:54 -07007390 @Override
7391 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007392 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007393 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7394 return;
7395 }
7396
Svet Ganovcc087f82015-05-12 20:35:54 -07007397 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007398
Svet Ganovcc087f82015-05-12 20:35:54 -07007399 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007400 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7401 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007402 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007403 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007404 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007405 setAllowedNetworkTypesForReason(subId,
7406 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7407 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7408 setAllowedNetworkTypesForReason(subId,
7409 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7410 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7411 setAllowedNetworkTypesForReason(subId,
7412 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7413 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Yomna Nasser3f777b62021-02-17 03:38:52 +00007414 setAllowedNetworkTypesForReason(subId,
7415 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G,
7416 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007417 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7418 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007419 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007420 // There has been issues when Sms raw table somehow stores orphan
7421 // fragments. They lead to garbled message when new fragments come
7422 // in and combined with those stale ones. In case this happens again,
7423 // user can reset all network settings which will clean up this table.
7424 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007425 // Clean up IMS settings as well here.
7426 int slotId = getSlotIndex(subId);
7427 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7428 ImsManager.getInstance(mApp, slotId).factoryReset();
7429 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007430
7431 // Erase modem config if erase modem on network setting is enabled.
7432 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7433 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7434 if (configValue != null && Boolean.parseBoolean(configValue)) {
7435 sendEraseModemConfig(getDefaultPhone());
7436 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007439 }
7440 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007441
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007442 private void cleanUpSmsRawTable(Context context) {
7443 ContentResolver resolver = context.getContentResolver();
7444 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7445 resolver.delete(uri, null, null);
7446 }
7447
Narayan Kamath1c496c22015-04-16 14:40:19 +01007448 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007449 public String getSimLocaleForSubscriber(int subId) {
7450 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7451 final Phone phone = getPhone(subId);
7452 if (phone == null) {
7453 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007454 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
chen xu5d3637b2019-01-21 23:31:38 -08007458 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007459 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007460 if (info == null) {
7461 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7462 return null;
7463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 // Try and fetch the locale from the carrier properties or from the SIM language
7465 // preferences (EF-PL and EF-LI)...
7466 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007468 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7469 if (localeFromDefaultSim != null) {
7470 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7471 if (DBG) log("Using locale from subId: " + subId + " locale: "
7472 + localeFromDefaultSim);
7473 return localeFromDefaultSim.toLanguageTag();
7474 } else {
7475 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 }
7477 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 // The SIM language preferences only store a language (e.g. fr = French), not an
7480 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7481 // the SIM and carrier preferences does not include a country we add the country
7482 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007483 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007485 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return mccLocale.toLanguageTag();
7487 }
7488
7489 if (DBG) log("No locale found - returning null");
7490 return null;
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007494 }
7495
7496 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007498 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007499 }
7500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 /**
7502 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7503 */
7504 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007506 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007507 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007508
Chenjie Yu1ba97252018-01-11 18:16:20 -08007509 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007510 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007511
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007512 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007513 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7514 * representing the state of the modem.
7515 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007516 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7517 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007518 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007519 */
7520 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007521 public void requestModemActivityInfo(ResultReceiver result) {
7522 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007523 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007527 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 } finally {
7529 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007530 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007531 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007532
Siddharth Rayb8114062018-06-17 15:02:38 -07007533 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7534 // less than total activity duration.
7535 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7536 if (info == null) {
7537 return false;
7538 }
7539 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007540 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7541 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7542
Siddharth Rayb8114062018-06-17 15:02:38 -07007543 return (info.isValid()
7544 && (info.getSleepTimeMillis() <= activityDurationMs)
7545 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007546 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007547 && (totalTxTimeMs <= activityDurationMs));
7548 }
7549
Jack Yu85bd38a2015-11-09 11:34:32 -08007550 /**
7551 * {@hide}
7552 * Returns the service state information on specified subscription.
7553 */
7554 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007555 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007558 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007559 return null;
7560 }
7561
Hall Liuf19c44f2018-11-27 14:38:17 -08007562 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7563 LocationAccessPolicy.checkLocationPermission(mApp,
7564 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7565 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007566 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007567 .setCallingPid(Binder.getCallingPid())
7568 .setCallingUid(Binder.getCallingUid())
7569 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007570 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007571 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007572 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7573 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007574 .build());
7575
7576 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7577 LocationAccessPolicy.checkLocationPermission(mApp,
7578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7579 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007580 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007581 .setCallingPid(Binder.getCallingPid())
7582 .setCallingUid(Binder.getCallingUid())
7583 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007584 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007586 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7587 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007588 .build());
7589 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7590 boolean hasFinePermission =
7591 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7592 boolean hasCoarsePermission =
7593 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7594
Jack Yu479f40e2020-10-27 21:29:25 -07007595 final Phone phone = getPhone(subId);
7596 if (phone == null) {
7597 return null;
7598 }
7599
Jordan Liu0f2bc442020-11-18 16:47:37 -08007600 final long identity = Binder.clearCallingIdentity();
7601
Jack Yu479f40e2020-10-27 21:29:25 -07007602 boolean isCallingPackageDataService = phone.getDataServicePackages()
7603 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007605 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7606 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7607 Rlog.d(LOG_TAG,
7608 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7609 return null;
7610 }
7611
Hall Liuf19c44f2018-11-27 14:38:17 -08007612 ServiceState ss = phone.getServiceState();
7613
7614 // Scrub out the location info in ServiceState depending on what level of access
7615 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007616 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007617 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7618 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007622 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007623
7624 /**
7625 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7626 *
7627 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7628 * voicemail ringtone.
7629 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7630 * PhoneAccount.
7631 */
7632 @Override
7633 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7637 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007638 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007645 }
7646
7647 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007648 * Sets the per-account voicemail ringtone.
7649 *
7650 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7651 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7652 *
7653 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7654 * voicemail ringtone.
7655 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7656 * PhoneAccount.
7657 */
7658 @Override
7659 public void setVoicemailRingtoneUri(String callingPackage,
7660 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007661 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007663 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7664 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7666 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7667 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669
7670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7673 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007674 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 }
7676 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007679 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007680 }
7681
7682 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007683 * Returns whether vibration is set for voicemail notification in Phone settings.
7684 *
7685 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7686 * voicemail vibration setting.
7687 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7688 */
7689 @Override
7690 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7694 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007695 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007702 }
7703
Youhan Wange64578a2016-05-02 15:32:42 -07007704 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007705 * Sets the per-account voicemail vibration.
7706 *
7707 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7708 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7709 *
7710 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7711 * voicemail vibration setting.
7712 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7713 * specific PhoneAccount.
7714 */
7715 @Override
7716 public void setVoicemailVibrationEnabled(String callingPackage,
7717 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007720 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7721 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7723 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7724 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007725 }
7726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7730 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007731 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 }
7733 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007736 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007737 }
7738
7739 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007740 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7741 *
7742 * @throws SecurityException if the caller does not have the required permission
7743 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007744 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007745 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007746 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007747 }
7748
7749 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007750 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7751 * permission.
7752 *
7753 * @throws SecurityException if the caller does not have the required permission
7754 */
7755 private void enforceSendSmsPermission() {
7756 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7757 }
7758
7759 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007760 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007761 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007762 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007763 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007764 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 final long identity = Binder.clearCallingIdentity();
7766 try {
7767 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 if (componentName == null) {
7770 throw new SecurityException(
7771 "Caller not current active visual voicemail package[null]");
7772 }
7773 String vvmPackage = componentName.getPackageName();
7774 if (!callingPackage.equals(vvmPackage)) {
7775 throw new SecurityException("Caller not current active visual voicemail package["
7776 + vvmPackage + "]");
7777 }
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007780 }
7781 }
7782
7783 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007784 * Return the application ID for the app type.
7785 *
7786 * @param subId the subscription ID that this request applies to.
7787 * @param appType the uicc app type.
7788 * @return Application ID for specificied app type, or null if no uicc.
7789 */
7790 @Override
7791 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007792 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007793 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794
7795 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007796 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 if (phone == null) {
7798 return null;
7799 }
7800 String aid = null;
7801 try {
7802 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7803 .getApplicationByType(appType).getAid();
7804 } catch (Exception e) {
7805 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7806 }
7807 return aid;
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007810 }
Youhan Wange64578a2016-05-02 15:32:42 -07007811 }
7812
Youhan Wang4001d252016-05-11 10:29:41 -07007813 /**
7814 * Return the Electronic Serial Number.
7815 *
7816 * @param subId the subscription ID that this request applies to.
7817 * @return ESN or null if error.
7818 */
7819 @Override
7820 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007821 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007822 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823
7824 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007825 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 if (phone == null) {
7827 return null;
7828 }
7829 String esn = null;
7830 try {
7831 esn = phone.getEsn();
7832 } catch (Exception e) {
7833 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7834 }
7835 return esn;
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007838 }
Youhan Wang4001d252016-05-11 10:29:41 -07007839 }
7840
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007841 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007842 * Return the Preferred Roaming List Version.
7843 *
7844 * @param subId the subscription ID that this request applies to.
7845 * @return PRLVersion or null if error.
7846 */
7847 @Override
7848 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007849 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007850 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851
7852 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007853 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 if (phone == null) {
7855 return null;
7856 }
7857 String cdmaPrlVersion = null;
7858 try {
7859 cdmaPrlVersion = phone.getCdmaPrlVersion();
7860 } catch (Exception e) {
7861 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7862 }
7863 return cdmaPrlVersion;
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007866 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007867 }
7868
7869 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007870 * Get snapshot of Telephony histograms
7871 * @return List of Telephony histograms
7872 * @hide
7873 */
7874 @Override
7875 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7877 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878
7879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 return RIL.getTelephonyRILTimingHistograms();
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
7884 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007885 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007886
7887 /**
7888 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007889 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7890 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007891 * Require system privileges. In the future we may add this to carrier APIs.
7892 *
Michele Berionne482f8202018-11-27 18:57:59 -08007893 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007894 */
7895 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007896 @TelephonyManager.SetCarrierRestrictionResult
7897 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007898 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007900
Michele Berionne482f8202018-11-27 18:57:59 -08007901 if (carrierRestrictionRules == null) {
7902 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007903 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 final long identity = Binder.clearCallingIdentity();
7906 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007907 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007908 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 } finally {
7910 Binder.restoreCallingIdentity(identity);
7911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007912 }
7913
7914 /**
7915 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007916 * Get the allowed carrier list and the excluded carrier list, including the priority between
7917 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007918 * Require system privileges. In the future we may add this to carrier APIs.
7919 *
Michele Berionne482f8202018-11-27 18:57:59 -08007920 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007921 */
7922 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007923 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007924 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007929 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7930 if (response instanceof CarrierRestrictionRules) {
7931 return (CarrierRestrictionRules) response;
7932 }
7933 // Response is an Exception of some kind,
7934 // which is signalled to the user as a NULL retval
7935 return null;
7936 } catch (Exception e) {
7937 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7938 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007942 }
7943
fionaxu59545b42016-05-25 15:53:37 -07007944 /**
fionaxu59545b42016-05-25 15:53:37 -07007945 * Action set from carrier signalling broadcast receivers to enable/disable radio
7946 * @param subId the subscription ID that this action applies to.
7947 * @param enabled control enable or disable radio.
7948 * {@hide}
7949 */
7950 @Override
7951 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7952 enforceModifyPermission();
7953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954
7955 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007956 if (phone == null) {
7957 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7958 return;
7959 }
7960 try {
7961 phone.carrierActionSetRadioEnabled(enabled);
7962 } catch (Exception e) {
7963 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 } finally {
7965 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007966 }
7967 }
7968
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007969 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007970 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7971 * network status based on which carrier apps could apply actions accordingly,
7972 * enable/disable default url handler for example.
7973 *
7974 * @param subId the subscription ID that this action applies to.
7975 * @param report control start/stop reporting the default network status.
7976 * {@hide}
7977 */
7978 @Override
7979 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7980 enforceModifyPermission();
7981 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982
7983 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007984 if (phone == null) {
7985 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7986 return;
7987 }
7988 try {
7989 phone.carrierActionReportDefaultNetworkStatus(report);
7990 } catch (Exception e) {
7991 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 } finally {
7993 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007994 }
7995 }
7996
7997 /**
fionaxud9622282017-07-17 17:51:30 -07007998 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7999 * @param subId the subscription ID that this action applies to.
8000 * {@hide}
8001 */
8002 @Override
8003 public void carrierActionResetAll(int subId) {
8004 enforceModifyPermission();
8005 final Phone phone = getPhone(subId);
8006 if (phone == null) {
8007 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8008 return;
8009 }
8010 try {
8011 phone.carrierActionResetAll();
8012 } catch (Exception e) {
8013 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8014 }
8015 }
8016
8017 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008018 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8019 * bug report is being generated.
8020 */
8021 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008022 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8024 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008025 writer.println("Permission Denial: can't dump Phone from pid="
8026 + Binder.getCallingPid()
8027 + ", uid=" + Binder.getCallingUid()
8028 + "without permission "
8029 + android.Manifest.permission.DUMP);
8030 return;
8031 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008033 }
Jack Yueb89b242016-06-22 13:27:47 -07008034
Brad Ebingerdac2f002018-04-03 15:17:52 -07008035 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008036 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8037 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8038 @NonNull String[] args) {
8039 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8040 this, in.getFileDescriptor(), out.getFileDescriptor(),
8041 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008042 }
8043
Jack Yueb89b242016-06-22 13:27:47 -07008044 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008045 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008046 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008047 * @param reason the reason the data enable change is taking place
8048 * @param enabled True if enabling the data, otherwise disabling.
8049 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008050 */
8051 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008052 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008053 boolean enabled) {
8054 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8055 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8056 try {
8057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008058 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008059 } catch (SecurityException se) {
8060 enforceModifyPermission();
8061 }
8062 } else {
8063 enforceModifyPermission();
8064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065
8066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 Phone phone = getPhone(subId);
8069 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008070 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8071 phone.carrierActionSetMeteredApnsEnabled(enabled);
8072 } else {
8073 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 }
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008078 }
8079 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008080
8081 /**
8082 * Get Client request stats
8083 * @return List of Client Request Stats
8084 * @hide
8085 */
8086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008087 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8088 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008090 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008091 return null;
8092 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008093 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 if (phone != null) {
8098 return phone.getClientRequestStats();
8099 }
8100
8101 return null;
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008105 }
8106
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008107 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008108 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008109 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008110 }
Jack Yueb4124c2017-02-16 15:32:43 -08008111
8112 /**
Grace Chen70990072017-03-24 17:21:30 -07008113 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008114 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008115 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008116 * @param state State of SIM (power down, power up, pass through)
8117 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8118 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8119 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008120 *
8121 **/
8122 @Override
Grace Chen70990072017-03-24 17:21:30 -07008123 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008124 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008125 Phone phone = PhoneFactory.getPhone(slotIndex);
8126
vagdeviaf9a5b92018-08-15 16:01:53 -07008127 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008132 phone.setSimPowerState(state, null, workSource);
8133 }
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
8137 }
8138
8139 /**
8140 * Set SIM card power state.
8141 *
8142 * @param slotIndex SIM slot id.
8143 * @param state State of SIM (power down, power up, pass through)
8144 * @param callback callback to trigger after success or failure
8145 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8146 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8147 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8148 *
8149 **/
8150 @Override
8151 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8152 IIntegerConsumer callback) {
8153 enforceModifyPermission();
8154 Phone phone = PhoneFactory.getPhone(slotIndex);
8155
8156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8157
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 if (phone != null) {
8161 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8162 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163 }
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008166 }
8167 }
Shuo Qiandd210312017-04-12 22:11:33 +00008168
Tyler Gunn65d45c22017-06-05 11:22:26 -07008169 private boolean isUssdApiAllowed(int subId) {
8170 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008171 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008172 if (configManager == null) {
8173 return false;
8174 }
8175 PersistableBundle pb = configManager.getConfigForSubId(subId);
8176 if (pb == null) {
8177 return false;
8178 }
8179 return pb.getBoolean(
8180 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8181 }
8182
Shuo Qiandd210312017-04-12 22:11:33 +00008183 /**
8184 * Check if phone is in emergency callback mode
8185 * @return true if phone is in emergency callback mode
8186 * @param subId sub id
8187 */
goneil9c5f4872017-12-05 14:07:56 -08008188 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008189 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008190 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192
8193 final long identity = Binder.clearCallingIdentity();
8194 try {
8195 if (phone != null) {
8196 return phone.isInEcm();
8197 } else {
8198 return false;
8199 }
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008202 }
8203 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008204
8205 /**
8206 * Get the current signal strength information for the given subscription.
8207 * Because this information is not updated when the device is in a low power state
8208 * it should not be relied-upon to be current.
8209 * @param subId Subscription index
8210 * @return the most recent cached signal strength info from the modem
8211 */
8212 @Override
8213 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone p = getPhone(subId);
8217 if (p == null) {
8218 return null;
8219 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 return p.getSignalStrength();
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
8224 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008225 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008226
Pengquan Meng77b7f132018-08-22 14:49:57 -07008227 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008228 * Get the current modem radio state for the given slot.
8229 * @param slotIndex slot index.
8230 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008231 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008232 * @return the current radio power state from the modem
8233 */
8234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008235 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008236 Phone phone = PhoneFactory.getPhone(slotIndex);
8237 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8239 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008240 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8241 }
8242
8243 final long identity = Binder.clearCallingIdentity();
8244 try {
8245 return phone.getRadioPowerState();
8246 } finally {
8247 Binder.restoreCallingIdentity(identity);
8248 }
8249 }
8250 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8251 }
8252
8253 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008254 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8255 *
8256 * <p>Requires one of the following permissions:
8257 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8258 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8259 * privileges.
8260 *
8261 * @param subId subscription id
8262 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8263 * {@code false}.
8264 */
8265 @Override
8266 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008267 try {
8268 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8269 null);
8270 } catch (Exception e) {
8271 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8272 mApp, subId, "isDataRoamingEnabled");
8273 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008274
Pengquan Menga1bb6272018-09-06 09:59:22 -07008275 boolean isEnabled = false;
8276 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008277 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008278 Phone phone = getPhone(subId);
8279 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008280 } finally {
8281 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008282 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008283 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008284 }
8285
8286
8287 /**
8288 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8289 *
8290 * <p> Requires permission:
8291 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8292 * privileges.
8293 *
8294 * @param subId subscription id
8295 * @param isEnabled {@code true} means enable, {@code false} means disable.
8296 */
8297 @Override
8298 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8300 mApp, subId, "setDataRoamingEnabled");
8301
Pengquan Menga1bb6272018-09-06 09:59:22 -07008302 final long identity = Binder.clearCallingIdentity();
8303 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008304 Phone phone = getPhone(subId);
8305 if (phone != null) {
8306 phone.setDataRoamingEnabled(isEnabled);
8307 }
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008310 }
8311 }
8312
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008313 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008314 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008315 TelephonyPermissions
8316 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008317 mApp, subId, "isManualNetworkSelectionAllowed");
8318
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008319 boolean isAllowed = true;
8320 final long identity = Binder.clearCallingIdentity();
8321 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008322 Phone phone = getPhone(subId);
8323 if (phone != null) {
8324 isAllowed = phone.isCspPlmnEnabled();
8325 }
8326 } finally {
8327 Binder.restoreCallingIdentity(identity);
8328 }
8329 return isAllowed;
8330 }
8331
8332 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008333 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008334 // Verify that tha callingPackage belongs to the calling UID
8335 mApp.getSystemService(AppOpsManager.class)
8336 .checkPackage(Binder.getCallingUid(), callingPackage);
8337
Jordan Liu1e142fc2019-04-22 15:10:43 -07008338 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008339 try {
8340 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008341 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008342 } catch (SecurityException e) {
8343 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8344 // has carrier privileges on an active UICC
8345 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8346 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008347 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008348 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008349 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008350
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008353 UiccController uiccController = UiccController.getInstance();
8354 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008355 if (hasReadPermission) {
8356 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008357 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008358
8359 // Remove private info if the caller doesn't have access
8360 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8361 for (UiccCardInfo cardInfo : cardInfos) {
8362 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8363 // is available
8364 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8365 if (card == null || card.getUiccProfile() == null) {
8366 // assume no access if the card or profile is unavailable
8367 filteredInfos.add(cardInfo.getUnprivileged());
8368 continue;
8369 }
8370 UiccProfile profile = card.getUiccProfile();
8371 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8372 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8373 filteredInfos.add(cardInfo);
8374 } else {
8375 filteredInfos.add(cardInfo.getUnprivileged());
8376 }
8377 }
8378 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
8382 }
8383
8384 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008385 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008386 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 final long identity = Binder.clearCallingIdentity();
8389 try {
8390 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8391 if (slots == null) {
8392 Rlog.i(LOG_TAG, "slots is null.");
8393 return null;
8394 }
8395
8396 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8397 for (int i = 0; i < slots.length; i++) {
8398 UiccSlot slot = slots[i];
8399 if (slot == null) {
8400 continue;
8401 }
8402
Jordan Liu7be7e652019-05-06 18:55:02 +00008403 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008404 UiccCard card = slot.getUiccCard();
8405 if (card != null) {
8406 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008407 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008408 cardId = slot.getEid();
8409 if (TextUtils.isEmpty(cardId)) {
8410 cardId = slot.getIccId();
8411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 }
8413
Jordan Liu857451f2019-05-09 16:35:35 -07008414 if (cardId != null) {
8415 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8416 // if cardId is an EID, it's all digits so this is fine
8417 cardId = IccUtils.stripTrailingFs(cardId);
8418 }
8419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420 int cardState = 0;
8421 switch (slot.getCardState()) {
8422 case CARDSTATE_ABSENT:
8423 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8424 break;
8425 case CARDSTATE_PRESENT:
8426 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8427 break;
8428 case CARDSTATE_ERROR:
8429 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8430 break;
8431 case CARDSTATE_RESTRICTED:
8432 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8433 break;
8434 default:
8435 break;
8436
8437 }
8438
8439 infos[i] = new UiccSlotInfo(
8440 slot.isActive(),
8441 slot.isEuicc(),
8442 cardId,
8443 cardState,
8444 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008445 slot.isExtendedApduSupported(),
8446 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 }
8448 return infos;
8449 } finally {
8450 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008451 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008452 }
8453
8454 @Override
8455 public boolean switchSlots(int[] physicalSlots) {
8456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008464 }
Jack Yu4c988042018-02-27 15:30:01 -08008465
8466 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008467 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 return UiccController.getInstance().getCardIdForDefaultEuicc();
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 }
8475
Pengquan Meng85728fb2018-03-12 16:31:21 -07008476 /**
goneil47ffb6e2018-04-06 15:40:58 -07008477 * A test API to reload the UICC profile.
8478 *
8479 * <p>Requires that the calling app has permission
8480 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8481 * @hide
8482 */
8483 @Override
8484 public void refreshUiccProfile(int subId) {
8485 enforceModifyPermission();
8486
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 Phone phone = getPhone(subId);
8490 if (phone == null) {
8491 return;
8492 }
8493 UiccCard uiccCard = phone.getUiccCard();
8494 if (uiccCard == null) {
8495 return;
8496 }
8497 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8498 if (uiccProfile == null) {
8499 return;
8500 }
8501 uiccProfile.refresh();
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
8505 }
8506
8507 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008508 * Returns false if the mobile data is disabled by default, otherwise return true.
8509 */
8510 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008511 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008512 }
8513
8514 /**
8515 * Returns true if the data roaming is enabled by default, i.e the system property
8516 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8517 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8518 */
8519 private boolean getDefaultDataRoamingEnabled(int subId) {
8520 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008521 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008522 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008523 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8524 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8525 return isDataRoamingEnabled;
8526 }
8527
8528 /**
8529 * Returns the default network type for the given {@code subId}, if the default network type is
8530 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8531 */
8532 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008533 List<Integer> list = TelephonyProperties.default_network();
8534 int phoneId = mSubscriptionController.getPhoneId(subId);
8535 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8536 return list.get(phoneId);
8537 }
8538 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008539 }
fionaxua13278b2018-03-21 00:08:13 -07008540
8541 @Override
8542 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008543 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545
8546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 final Phone phone = getPhone(subId);
8549 if (phone == null) {
8550 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8551 return;
8552 }
chen xueaba88a2019-03-15 13:15:10 -07008553 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8554 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008555 if (carrierPrivilegeRules == null) {
8556 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8557 } else {
8558 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008560 } finally {
8561 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008562 }
fionaxua13278b2018-03-21 00:08:13 -07008563 }
8564
8565 @Override
8566 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008567 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008568
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 final Phone phone = getPhone(subId);
8572 if (phone == null) {
8573 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8574 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8575 }
8576 return phone.getCarrierIdListVersion();
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008579 }
fionaxua13278b2018-03-21 00:08:13 -07008580 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008581
8582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008583 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8584 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008586 mApp, subId, callingPackage, callingFeatureId,
8587 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008588 return -1;
8589 }
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
8597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008598
8599 @Override
8600 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008601 TelephonyPermissions
8602 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008603 mApp, subId, "getCdmaRoamingMode");
8604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
8611 }
8612
8613 @Override
8614 public boolean setCdmaRoamingMode(int subId, int mode) {
8615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8616 mApp, subId, "setCdmaRoamingMode");
8617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625
8626 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008627 public int getCdmaSubscriptionMode(int subId) {
8628 TelephonyPermissions
8629 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8630 mApp, subId, "getCdmaSubscriptionMode");
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
8638 }
8639
8640 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008641 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8643 mApp, subId, "setCdmaSubscriptionMode");
8644
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
8647 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008652
sqianc5eccab2018-10-19 18:46:41 -07008653 @Override
sqian8c685422019-02-22 15:55:18 -08008654 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008655 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008657 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8658 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008659 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8660 }
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
sqian854d44b2018-12-12 16:48:18 -08008663 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8664 for (Phone phone: PhoneFactory.getPhones()) {
8665 if (phone.getEmergencyNumberTracker() != null
8666 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8667 emergencyNumberListInternal.put(
8668 phone.getSubId(),
8669 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8670 }
sqian11b7a0e2018-12-05 18:48:28 -08008671 }
sqian854d44b2018-12-12 16:48:18 -08008672 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
sqianc5eccab2018-10-19 18:46:41 -07008676 }
8677
8678 @Override
sqian8c685422019-02-22 15:55:18 -08008679 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008680 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008681 if (!exactMatch) {
8682 TelephonyPermissions
8683 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008684 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008685 }
8686 final long identity = Binder.clearCallingIdentity();
8687 try {
sqian854d44b2018-12-12 16:48:18 -08008688 for (Phone phone: PhoneFactory.getPhones()) {
8689 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008690 && phone.getEmergencyNumberTracker()
8691 .isEmergencyNumber(number, exactMatch)) {
8692 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008693 }
sqian11b7a0e2018-12-05 18:48:28 -08008694 }
8695 return false;
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
8699 }
8700
sqianf4ca7ed2019-01-15 18:32:07 -08008701 /**
8702 * Update emergency number list for test mode.
8703 */
8704 @Override
8705 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8707 "updateEmergencyNumberListTestMode");
8708
8709 final long identity = Binder.clearCallingIdentity();
8710 try {
8711 for (Phone phone: PhoneFactory.getPhones()) {
8712 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8713 if (tracker != null) {
8714 tracker.executeEmergencyNumberTestModeCommand(action, num);
8715 }
8716 }
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
8722 /**
8723 * Get the full emergency number list for test mode.
8724 */
8725 @Override
8726 public List<String> getEmergencyNumberListTestMode() {
8727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8728 "getEmergencyNumberListTestMode");
8729
8730 final long identity = Binder.clearCallingIdentity();
8731 try {
8732 Set<String> emergencyNumbers = new HashSet<>();
8733 for (Phone phone: PhoneFactory.getPhones()) {
8734 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8735 if (tracker != null) {
8736 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8737 emergencyNumbers.add(num.getNumber());
8738 }
8739 }
8740 }
8741 return new ArrayList<>(emergencyNumbers);
8742 } finally {
8743 Binder.restoreCallingIdentity(identity);
8744 }
8745 }
8746
chen xud6b45bd2018-10-30 22:27:10 -07008747 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008748 public int getEmergencyNumberDbVersion(int subId) {
8749 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8750
8751 final long identity = Binder.clearCallingIdentity();
8752 try {
8753 final Phone phone = getPhone(subId);
8754 if (phone == null) {
8755 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8756 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8757 }
8758 return phone.getEmergencyNumberDbVersion();
8759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 }
8763
8764 @Override
8765 public void notifyOtaEmergencyNumberDbInstalled() {
8766 enforceModifyPermission();
8767
8768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 for (Phone phone: PhoneFactory.getPhones()) {
8771 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8772 if (tracker != null) {
8773 tracker.updateOtaEmergencyNumberDatabase();
8774 }
8775 }
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
8779 }
8780
8781 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008782 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008783 enforceActiveEmergencySessionPermission();
8784
8785 final long identity = Binder.clearCallingIdentity();
8786 try {
8787 for (Phone phone: PhoneFactory.getPhones()) {
8788 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8789 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008790 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8791 }
8792 }
8793 } finally {
8794 Binder.restoreCallingIdentity(identity);
8795 }
8796 }
8797
8798 @Override
8799 public void resetOtaEmergencyNumberDbFilePath() {
8800 enforceActiveEmergencySessionPermission();
8801
8802 final long identity = Binder.clearCallingIdentity();
8803 try {
8804 for (Phone phone: PhoneFactory.getPhones()) {
8805 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8806 if (tracker != null) {
8807 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008808 }
8809 }
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
8814
8815 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008816 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8817 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8818 Phone phone = getPhone(subId);
8819 if (phone == null) {
8820 return null;
8821 }
8822 final long identity = Binder.clearCallingIdentity();
8823 try {
8824 UiccProfile profile = UiccController.getInstance()
8825 .getUiccProfileForPhone(phone.getPhoneId());
8826 if (profile != null) {
8827 return profile.getCertsFromCarrierPrivilegeAccessRules();
8828 }
8829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 return null;
8833 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008834
8835 /**
8836 * Enable or disable a modem stack.
8837 */
8838 @Override
8839 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8840 enforceModifyPermission();
8841
8842 final long identity = Binder.clearCallingIdentity();
8843 try {
8844 Phone phone = PhoneFactory.getPhone(slotIndex);
8845 if (phone == null) {
8846 return false;
8847 } else {
8848 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8849 }
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
8852 }
8853 }
Michelecea4cf22018-12-21 15:00:11 -08008854
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008855 /**
8856 * Whether a modem stack is enabled or not.
8857 */
8858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008859 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8860 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008861 Phone phone = PhoneFactory.getPhone(slotIndex);
8862 if (phone == null) return false;
8863
8864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008865 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8866 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008867 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8868 }
8869
8870 final long identity = Binder.clearCallingIdentity();
8871 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008872 try {
8873 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8874 } catch (NoSuchElementException ex) {
8875 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8876 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008877 } finally {
8878 Binder.restoreCallingIdentity(identity);
8879 }
8880 }
8881
Michelecea4cf22018-12-21 15:00:11 -08008882 @Override
Michele0ea7d782019-03-19 14:58:42 -07008883 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008884 enforceModifyPermission();
8885
8886 final long identity = Binder.clearCallingIdentity();
8887 try {
8888 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008889 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008890 .commit();
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
8893 }
8894 }
8895
8896 @Override
Michele0ea7d782019-03-19 14:58:42 -07008897 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008898 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008900 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8901 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008902 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008903 }
Michelecea4cf22018-12-21 15:00:11 -08008904
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
Michele0ea7d782019-03-19 14:58:42 -07008907 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008908 } finally {
8909 Binder.restoreCallingIdentity(identity);
8910 }
8911 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008912
Michele0ea7d782019-03-19 14:58:42 -07008913 @TelephonyManager.IsMultiSimSupportedResult
8914 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008915 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8916 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8917 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008918 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008920 }
8921 // Check if the hardware supports multisim functionality. If usage of multisim is not
8922 // supported by the modem, indicate that it is restricted.
8923 PhoneCapability staticCapability =
8924 mPhoneConfigurationManager.getStaticPhoneCapability();
8925 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008926 loge("isMultiSimSupportedInternal: no static configuration available");
8927 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008928 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008929 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008930 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8931 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008932 }
8933 // Check if support of multiple SIMs is restricted by carrier
8934 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008935 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008936 }
8937
Michele0ea7d782019-03-19 14:58:42 -07008938 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008939 }
8940
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008941 /**
8942 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008943 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8944 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8945 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008946 * @param numOfSims number of active sims we want to switch to
8947 */
8948 @Override
8949 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008950 if (numOfSims == 1) {
8951 enforceModifyPermission();
8952 } else {
8953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8954 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8955 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008956 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008957
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008958 try {
Michele30b57b22019-03-01 12:01:14 -08008959 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008960 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008961 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8962 return;
8963 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008964 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8965 } finally {
8966 Binder.restoreCallingIdentity(identity);
8967 }
8968 }
8969
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008970 @Override
8971 public boolean isApplicationOnUicc(int subId, int appType) {
8972 enforceReadPrivilegedPermission("isApplicationOnUicc");
8973 Phone phone = getPhone(subId);
8974 if (phone == null) {
8975 return false;
8976 }
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 UiccCard uiccCard = phone.getUiccCard();
8980 if (uiccCard == null) {
8981 return false;
8982 }
8983 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8984 if (uiccProfile == null) {
8985 return false;
8986 }
8987 if (TelephonyManager.APPTYPE_SIM <= appType
8988 && appType <= TelephonyManager.APPTYPE_ISIM) {
8989 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8990 }
8991 return false;
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
8995 }
8996
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008997 /**
chen xub4baa772019-04-03 10:23:41 -07008998 * Get whether making changes to modem configurations will trigger reboot.
8999 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009000 */
9001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009002 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9003 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009005 mApp, subId, callingPackage, callingFeatureId,
9006 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009007 return false;
9008 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016
Nathan Harold29f5f052019-02-15 13:41:57 -08009017 private void updateModemStateMetrics() {
9018 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9019 // TODO: check the state for each modem if the api is ready.
9020 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9021 }
9022
Pengquan Meng3889a572019-01-23 11:16:29 -08009023 @Override
9024 public int[] getSlotsMapping() {
9025 enforceReadPrivilegedPermission("getSlotsMapping");
9026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9030 // All logical slots should have a mapping to a physical slot.
9031 int[] logicalSlotsMapping = new int[phoneCount];
9032 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9033 for (int i = 0; i < slotInfos.length; i++) {
9034 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9035 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9036 }
9037 }
9038 return logicalSlotsMapping;
9039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009043
9044 /**
9045 * Get the IRadio HAL Version
9046 */
9047 @Override
9048 public int getRadioHalVersion() {
9049 Phone phone = getDefaultPhone();
9050 if (phone == null) return -1;
9051 HalVersion hv = phone.getHalVersion();
9052 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9053 return hv.major * 100 + hv.minor;
9054 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009055
9056 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009057 * Get the current calling package name.
9058 * @return the current calling package name
9059 */
9060 @Override
9061 public String getCurrentPackageName() {
9062 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9063 }
9064
9065 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009066 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9067 * corresponding network requests on a subId.
9068 *
9069 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009070 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009071 * 2) APN is un-metered for this subscription, or
9072 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009073 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009074 *
9075 * @return whether data is allowed for a apn type.
9076 *
9077 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009078 */
9079 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009080 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009081 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9082 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009083
9084 // Now that all security checks passes, perform the operation as ourselves.
9085 final long identity = Binder.clearCallingIdentity();
9086 try {
9087 Phone phone = getPhone(subId);
9088 if (phone == null) return false;
9089
Jack Yu41407ee2019-05-13 16:54:09 -07009090 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009091 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009098 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009099 enforceReadPrivilegedPermission("isApnMetered");
9100
9101 // Now that all security checks passes, perform the operation as ourselves.
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 Phone phone = getPhone(subId);
9105 if (phone == null) return true; // By default return true.
9106
Jack Yu41407ee2019-05-13 16:54:09 -07009107 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009112
9113 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009114 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9115 int subscriptionId, IBooleanConsumer resultCallback) {
9116 enforceModifyPermission();
9117 long token = Binder.clearCallingIdentity();
9118 try {
9119 Phone phone = getPhone(subscriptionId);
9120 if (phone == null) {
9121 try {
9122 if (resultCallback != null) {
9123 resultCallback.accept(false);
9124 }
9125 } catch (RemoteException e) {
9126 // ignore
9127 }
9128 return;
9129 }
9130 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9131 Pair.create(specifiers, (x) -> {
9132 try {
9133 if (resultCallback != null) {
9134 resultCallback.accept(x);
9135 }
9136 } catch (RemoteException e) {
9137 // ignore
9138 }
9139 });
9140 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9141 } finally {
9142 Binder.restoreCallingIdentity(token);
9143 }
9144 }
9145
9146 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009147 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9148 TelephonyPermissions
9149 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9150 mApp, subId, "getSystemSelectionChannels");
9151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9152 final long identity = Binder.clearCallingIdentity();
9153 try {
9154 List<RadioAccessSpecifier> specifiers =
9155 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9156 null, subId, workSource);
9157 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9158 return specifiers;
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
9162 }
9163
9164 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009165 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009166 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009167 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9168 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9169 if (iccRecords == null) {
9170 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9171 return false;
9172 }
9173 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9174 }
9175
9176 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009177 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9178 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009179 if (callingPackage == null) {
9180 callingPackage = getCurrentPackageName();
9181 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009182 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9183 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009184 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9185 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009186 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9187 }
9188 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9189 Intent intent = new Intent();
9190 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9191 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9192 // Bring up choose default SMS subscription dialog right now
9193 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9194 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9195 mApp.startActivity(intent);
9196 }
chen xud5ca2d52019-05-28 15:20:57 -07009197
9198 @Override
9199 public String getMmsUAProfUrl(int subId) {
9200 //TODO investigate if this API should require proper permission check in R b/133791609
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009203 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9204 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9205 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9206 return carrierUAProfUrl;
9207 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009208 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9209 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
9215 @Override
9216 public String getMmsUserAgent(int subId) {
9217 //TODO investigate if this API should require proper permission check in R b/133791609
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009220 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9221 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9222 if (!TextUtils.isEmpty(carrierUserAgent)) {
9223 return carrierUserAgent;
9224 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009225 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9226 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
9230 }
Jack Yub07d4972019-05-28 16:12:25 -07009231
9232 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009233 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9234 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009235
Jack Yub07d4972019-05-28 16:12:25 -07009236 final long identity = Binder.clearCallingIdentity();
9237 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009238 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009239 if (phone == null) return false;
9240
Hall Liua62f5da2020-09-25 10:42:19 -07009241 switch (policy) {
9242 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9243 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9244 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9245 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9246 default:
9247 throw new IllegalArgumentException(policy + " is not a valid policy");
9248 }
Jack Yub07d4972019-05-28 16:12:25 -07009249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
9253
9254 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009255 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009256 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009257 enforceModifyPermission();
9258
changbettyd5c246e2019-12-24 15:40:37 +08009259 final long identity = Binder.clearCallingIdentity();
9260 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009261 Phone phone = getPhone(subscriptionId);
9262 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009263
Hall Liua62f5da2020-09-25 10:42:19 -07009264 switch (policy) {
9265 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9266 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9267 break;
9268 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9269 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9270 break;
9271 default:
9272 throw new IllegalArgumentException(policy + " is not a valid policy");
9273 }
changbettyd5c246e2019-12-24 15:40:37 +08009274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 }
9278
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009279 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009280 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009281 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9282 * otherwise.
9283 */
9284 @Override
9285 public void setCepEnabled(boolean isCepEnabled) {
9286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9287
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9291 for (Phone phone : PhoneFactory.getPhones()) {
9292 Phone defaultPhone = phone.getImsPhone();
9293 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9294 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9295 ImsPhoneCallTracker imsPhoneCallTracker =
9296 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9297 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9298 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9299 + imsPhone.getMsisdn());
9300 }
9301 }
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
allenwtsu46dcc572020-01-08 18:24:03 +08009306
9307 /**
9308 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9309 *
9310 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9311 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9312 * before being read.
9313 */
9314 @Override
9315 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9316 isCompressed) {
9317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9318 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009319 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9320 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9321 }
9322 if (!isImsAvailableOnDevice()) {
9323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9324 "IMS not available on device.");
9325 }
9326
9327 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009328 try {
Hui Wang761a6682020-10-31 05:12:53 +00009329 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009332 }
9333 }
zoey chene02881a2019-12-30 16:11:23 +08009334
9335 @Override
9336 public boolean isIccLockEnabled(int subId) {
9337 enforceReadPrivilegedPermission("isIccLockEnabled");
9338
9339 // Now that all security checks passes, perform the operation as ourselves.
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 Phone phone = getPhone(subId);
9343 if (phone != null && phone.getIccCard() != null) {
9344 return phone.getIccCard().getIccLockEnabled();
9345 } else {
9346 return false;
9347 }
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
9353 /**
9354 * Set the ICC pin lock enabled or disabled.
9355 *
9356 * @return an integer representing the status of IccLock enabled or disabled in the following
9357 * three cases:
9358 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9359 * successfully.
9360 * - Positive number and zero for remaining password attempts.
9361 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9362 *
9363 */
9364 @Override
9365 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9366 enforceModifyPermission();
9367
9368 Phone phone = getPhone(subId);
9369 if (phone == null) {
9370 return 0;
9371 }
9372 // Now that all security checks passes, perform the operation as ourselves.
9373 final long identity = Binder.clearCallingIdentity();
9374 try {
9375 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9376 new Pair<Boolean, String>(enabled, password), phone, null);
9377 return attemptsRemaining;
9378
9379 } catch (Exception e) {
9380 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 return 0;
9385 }
9386
9387 /**
9388 * Change the ICC password used in ICC pin lock.
9389 *
9390 * @return an integer representing the status of IccLock changed in the following three cases:
9391 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9392 * - Positive number and zero for remaining password attempts.
9393 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9394 *
9395 */
9396 @Override
9397 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9398 enforceModifyPermission();
9399
9400 Phone phone = getPhone(subId);
9401 if (phone == null) {
9402 return 0;
9403 }
9404 // Now that all security checks passes, perform the operation as ourselves.
9405 final long identity = Binder.clearCallingIdentity();
9406 try {
9407 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9408 new Pair<String, String>(oldPassword, newPassword), phone, null);
9409 return attemptsRemaining;
9410
9411 } catch (Exception e) {
9412 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9413 } finally {
9414 Binder.restoreCallingIdentity(identity);
9415 }
9416 return 0;
9417 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009418
9419 /**
9420 * Request for receiving user activity notification
9421 */
9422 @Override
9423 public void requestUserActivityNotification() {
9424 if (!mNotifyUserActivity.get()
9425 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9426 mNotifyUserActivity.set(true);
9427 }
9428 }
9429
9430 /**
9431 * Called when userActivity is signalled in the power manager.
9432 * This is safe to call from any thread, with any window manager locks held or not.
9433 */
9434 @Override
9435 public void userActivity() {
9436 // ***************************************
9437 // * Inherited from PhoneWindowManager *
9438 // ***************************************
9439 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9440 // WITH ITS LOCKS HELD.
9441 //
9442 // This code must be VERY careful about the locks
9443 // it acquires.
9444 // In fact, the current code acquires way too many,
9445 // and probably has lurking deadlocks.
9446
9447 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9448 throw new SecurityException("Only the OS may call notifyUserActivity()");
9449 }
9450
9451 if (mNotifyUserActivity.getAndSet(false)) {
9452 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9453 USER_ACTIVITY_NOTIFICATION_DELAY);
9454 }
9455 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009456
9457 @Override
9458 public boolean canConnectTo5GInDsdsMode() {
9459 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9460 }
Jack Yud10cdd42020-09-28 20:28:01 -07009461
9462 @Override
9463 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9464 String callingFeatureId) {
9465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9466 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9467 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9468 }
9469
9470 Phone phone = getPhone(subId);
9471 if (phone == null) {
9472 throw new RuntimeException("phone is not available");
9473 }
9474 // Now that all security checks passes, perform the operation as ourselves.
9475 final long identity = Binder.clearCallingIdentity();
9476 try {
9477 return phone.getEquivalentHomePlmns();
9478 } finally {
9479 Binder.restoreCallingIdentity(identity);
9480 }
9481 }
Daniel Bright59e67312020-11-13 11:49:37 -08009482
9483 @Override
9484 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009485 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9486 Set<String> radioInterfaceCapabilities =
Daniel Bright59e67312020-11-13 11:49:37 -08009487 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9488 if (radioInterfaceCapabilities == null) {
9489 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009490 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009491 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009492 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009493
Hui Wang641e81c2020-10-12 12:14:23 -07009494 @Override
9495 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9496 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009497 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9498 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9499 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9500 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9501 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009502 if (DBG) {
9503 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9504 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9505 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9506 }
9507
9508 if (!SubscriptionManager.isValidSubscriptionId(subId)
9509 || appType < TelephonyManager.APPTYPE_UNKNOWN
9510 || appType > TelephonyManager.APPTYPE_ISIM
9511 || nafUrl == null || securityProtocol == null || callback == null) {
9512 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9513 if (callback != null) {
9514 try {
9515 callback.onAuthenticationFailure(
9516 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9517 } catch (RemoteException exception) {
9518 log("Fail to notify onAuthenticationFailure due to " + exception);
9519 }
9520 return;
9521 }
9522 }
9523
9524 final long token = Binder.clearCallingIdentity();
9525 try {
9526 getGbaManager(subId).bootstrapAuthenticationRequest(
9527 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9528 forceBootStrapping, callback));
9529 } finally {
9530 Binder.restoreCallingIdentity(token);
9531 }
9532 }
9533
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009534 /**
9535 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9536 * requested radio power state will actually be set. See {@link
9537 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9538 *
9539 * @param subId the subscription ID of the phone requesting to set the radio power state.
9540 * @param enable {@code true} if trying to turn radio on.
9541 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9542 * false}.
9543 */
9544 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9545 Phone phone = getPhone(subId);
9546 if (phone != null) {
9547 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9548 return true;
9549 }
9550 return false;
9551 }
9552
9553 private int handleDataThrottlingRequest(int subId,
9554 DataThrottlingRequest dataThrottlingRequest) {
9555 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9556 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9557 if (!setRadioPowerForThermal(subId, true)) {
9558 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9559 }
9560
9561 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9562
9563 int thermalMitigationResult =
9564 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9565 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9566 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9567 }
9568 return thermalMitigationResult;
9569 }
9570
9571 /**
9572 * Thermal mitigation request to control functionalities at modem.
9573 *
9574 * @param subId the id of the subscription.
9575 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9576 *
9577 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9578 */
9579 @Override
9580 @ThermalMitigationResult
9581 public int sendThermalMitigationRequest(
9582 int subId,
9583 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9584 enforceModifyPermission();
9585
9586 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9587 final long identity = Binder.clearCallingIdentity();
9588
9589 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9590 try {
9591 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9592 switch (thermalMitigationAction) {
9593 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9594 thermalMitigationResult =
9595 handleDataThrottlingRequest(subId,
9596 thermalMitigationRequest.getDataThrottlingRequest());
9597 break;
9598 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9599 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9600 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9601 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9602 }
9603
9604 // Ensure that radio is on. If not able to power on due to phone being
9605 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9606 if (!setRadioPowerForThermal(subId, true)) {
9607 thermalMitigationResult =
9608 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9609 break;
9610 }
9611
9612 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9613 false);
9614 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9615 break;
9616 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9617 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9618 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9619 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9620 }
9621
9622 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9623 if (registry != null) {
9624 TelephonyConnectionService service =
9625 registry.getTelephonyConnectionService();
9626 Phone phone = getPhone(subId);
9627 if (phone == null) {
9628 thermalMitigationResult =
9629 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9630 break;
9631 }
9632
9633 if (PhoneConstantConversions.convertCallState(phone.getState())
9634 != TelephonyManager.CALL_STATE_IDLE
9635 || phone.isInEmergencySmsMode() || phone.isInEcm()
9636 || (service != null && service.isEmergencyCallPending())) {
9637 String errorMessage = "Phone state is not valid. call state = "
9638 + PhoneConstantConversions.convertCallState(phone.getState())
9639 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9640 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9641 errorMessage += service == null
9642 ? " TelephonyConnectionService is null"
9643 : " isEmergencyCallPending = "
9644 + service.isEmergencyCallPending();
9645 Log.e(LOG_TAG, errorMessage);
9646 thermalMitigationResult =
9647 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9648 break;
9649 }
9650 } else {
9651 thermalMitigationResult =
9652 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9653 break;
9654 }
9655
9656 // Turn radio off. If not able to power off due to phone being unavailable,
9657 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9658 if (!setRadioPowerForThermal(subId, false)) {
9659 thermalMitigationResult =
9660 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9661 break;
9662 }
9663 thermalMitigationResult =
9664 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9665 break;
9666 default:
9667 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9668 + "not exist. Requested action: " + thermalMitigationAction);
9669 }
9670 } catch (IllegalArgumentException e) {
9671 throw e;
9672 } catch (Exception e) {
9673 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9674 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678
9679 if (DBG) {
9680 log("thermalMitigationRequest returning with thermalMitigationResult: "
9681 + thermalMitigationResult);
9682 }
9683
9684 return thermalMitigationResult;
9685 }
Hui Wang641e81c2020-10-12 12:14:23 -07009686
9687 /**
9688 * Set the GbaService Package Name that Telephony will bind to.
9689 *
9690 * @param subId The sim that the GbaService is associated with.
9691 * @param packageName The name of the package to be replaced with.
9692 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9693 */
9694 @Override
9695 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9696 enforceModifyPermission();
9697
9698 final long identity = Binder.clearCallingIdentity();
9699 try {
9700 return getGbaManager(subId).overrideServicePackage(packageName);
9701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
9706 /**
9707 * Return the package name of the currently bound GbaService.
9708 *
9709 * @param subId The sim that the GbaService is associated with.
9710 * @return the package name of the GbaService configuration, null if GBA is not supported.
9711 */
9712 @Override
9713 public String getBoundGbaService(int subId) {
9714 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9715
9716 final long identity = Binder.clearCallingIdentity();
9717 try {
9718 return getGbaManager(subId).getServicePackage();
9719 } finally {
9720 Binder.restoreCallingIdentity(identity);
9721 }
9722 }
9723
9724 /**
9725 * Set the release time for telephony to unbind GbaService.
9726 *
9727 * @param subId The sim that the GbaService is associated with.
9728 * @param interval The release time to unbind GbaService by millisecond.
9729 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9730 */
9731 @Override
9732 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9733 enforceModifyPermission();
9734
9735 final long identity = Binder.clearCallingIdentity();
9736 try {
9737 return getGbaManager(subId).overrideReleaseTime(interval);
9738 } finally {
9739 Binder.restoreCallingIdentity(identity);
9740 }
9741 }
9742
9743 /**
9744 * Return the release time for telephony to unbind GbaService.
9745 *
9746 * @param subId The sim that the GbaService is associated with.
9747 * @return The release time to unbind GbaService by millisecond.
9748 */
9749 @Override
9750 public int getGbaReleaseTime(int subId) {
9751 enforceReadPrivilegedPermission("getGbaReleaseTime");
9752
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 return getGbaManager(subId).getReleaseTime();
9756 } finally {
9757 Binder.restoreCallingIdentity(identity);
9758 }
9759 }
9760
9761 private GbaManager getGbaManager(int subId) {
9762 GbaManager instance = GbaManager.getInstance(subId);
9763 if (instance == null) {
9764 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9765 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9766 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9767 }
9768 return instance;
9769 }
Hui Wang761a6682020-10-31 05:12:53 +00009770
9771 /**
9772 * indicate whether the device and the carrier can support
9773 * RCS VoLTE single registration.
9774 */
9775 @Override
9776 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009777 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9778 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9779 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9780 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009781
9782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9784 }
9785
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
9788 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9789 if (rpm != null) {
9790 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9791 }
9792 return false;
9793 } finally {
9794 Binder.restoreCallingIdentity(identity);
9795 }
9796 }
9797
9798 /**
9799 * Register RCS provisioning callback.
9800 */
9801 @Override
9802 public void registerRcsProvisioningChangedCallback(int subId,
9803 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009804 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9805 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9806 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9807 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009808
9809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9810 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9811 }
9812 if (!isImsAvailableOnDevice()) {
9813 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9814 "IMS not available on device.");
9815 }
9816
9817 final long identity = Binder.clearCallingIdentity();
9818 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009819 if (!RcsProvisioningMonitor.getInstance()
9820 .registerRcsProvisioningChangedCallback(subId, callback)) {
9821 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9822 "Service not available for the subscription.");
9823 }
Hui Wang761a6682020-10-31 05:12:53 +00009824 } finally {
9825 Binder.restoreCallingIdentity(identity);
9826 }
9827 }
9828
9829 /**
9830 * Unregister RCS provisioning callback.
9831 */
9832 @Override
9833 public void unregisterRcsProvisioningChangedCallback(int subId,
9834 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009835 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9836 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9837 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9838 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009839
9840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9841 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9842 }
9843 if (!isImsAvailableOnDevice()) {
9844 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9845 "IMS not available on device.");
9846 }
9847
9848 final long identity = Binder.clearCallingIdentity();
9849 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009850 RcsProvisioningMonitor.getInstance()
9851 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 /**
9858 * trigger RCS reconfiguration.
9859 */
9860 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009861 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9862 "triggerRcsReconfiguration",
9863 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009864
9865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9866 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9867 }
9868 if (!isImsAvailableOnDevice()) {
9869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9870 "IMS not available on device.");
9871 }
9872
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
9875 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
9881 /**
9882 * Provide the client configuration parameters of the RCS application.
9883 */
9884 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009885 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9886 "setRcsClientConfiguration",
9887 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009888
9889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9891 }
9892 if (!isImsAvailableOnDevice()) {
9893 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9894 "IMS not available on device.");
9895 }
9896
9897 final long identity = Binder.clearCallingIdentity();
9898
9899 try {
9900 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9901 if (configBinder == null) {
9902 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9903 } else {
9904 configBinder.setRcsClientConfiguration(rcc);
9905 }
9906 } catch (RemoteException e) {
9907 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 }
9912
9913 /**
9914 * Overrides the config of RCS VoLTE single registration enabled for the device.
9915 */
9916 @Override
9917 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9919 "setDeviceSingleRegistrationEnabledOverride");
9920 enforceModifyPermission();
9921
9922 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9923 : Boolean.parseBoolean(enabledStr);
9924 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009925 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009926 }
9927
9928 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009929 * Sends a device to device communication message. Only usable via shell.
9930 * @param message message to send.
9931 * @param value message value.
9932 */
9933 @Override
9934 public void sendDeviceToDeviceMessage(int message, int value) {
9935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009936 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009937 enforceModifyPermission();
9938
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
9941 TelephonyConnectionService service =
9942 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9943 if (service == null) {
9944 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9945 return;
9946 }
9947 service.sendTestDeviceToDeviceMessage(message, value);
9948 } finally {
9949 Binder.restoreCallingIdentity(identity);
9950 }
9951 }
9952
Tyler Gunnbabbda02021-02-10 11:05:02 -08009953 /**
9954 * Sets the specified device to device transport active.
9955 * @param transport The transport to set active.
9956 */
9957 @Override
9958 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
9959 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9960 "setActiveDeviceToDeviceTransport");
9961 enforceModifyPermission();
9962
9963 final long identity = Binder.clearCallingIdentity();
9964 try {
9965 TelephonyConnectionService service =
9966 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9967 if (service == null) {
9968 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
9969 return;
9970 }
9971 service.setActiveDeviceToDeviceTransport(transport);
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
Tyler Gunn92479152021-01-20 16:30:10 -08009976
9977 /**
Hui Wang761a6682020-10-31 05:12:53 +00009978 * Gets the config of RCS VoLTE single registration enabled for the device.
9979 */
9980 @Override
9981 public boolean getDeviceSingleRegistrationEnabled() {
9982 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9983 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9984 }
9985
9986 /**
9987 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9988 */
9989 @Override
9990 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9992 "setCarrierSingleRegistrationEnabledOverride");
9993 enforceModifyPermission();
9994
9995 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9996 : Boolean.parseBoolean(enabledStr);
9997 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9998 subId, enabled);
9999 }
10000
10001 /**
10002 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10003 */
10004 @Override
10005 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10006 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10007 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10008 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010009
10010 /**
10011 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10012 * their mobile plan.
10013 */
10014 @Override
10015 public String getMobileProvisioningUrl() {
10016 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10017 final long identity = Binder.clearCallingIdentity();
10018 try {
10019 return getDefaultPhone().getMobileProvisioningUrl();
10020 } finally {
10021 Binder.restoreCallingIdentity(identity);
10022 }
10023 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010024
James.cf Linbcdf8b32021-01-14 16:44:13 +080010025 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010026 * Get the EAB contact from the EAB database.
10027 */
10028 @Override
10029 public String getContactFromEab(String contact) {
10030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10031 enforceModifyPermission();
10032 final long identity = Binder.clearCallingIdentity();
10033 try {
10034 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10035 } finally {
10036 Binder.restoreCallingIdentity(identity);
10037 }
10038 }
10039
10040 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010041 * Remove the EAB contacts from the EAB database.
10042 */
10043 @Override
10044 public int removeContactFromEab(int subId, String contacts) {
10045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10046 enforceModifyPermission();
10047 final long identity = Binder.clearCallingIdentity();
10048 try {
10049 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10050 } finally {
10051 Binder.restoreCallingIdentity(identity);
10052 }
10053 }
10054
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010055 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010056 public boolean getDeviceUceEnabled() {
10057 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10058 final long identity = Binder.clearCallingIdentity();
10059 try {
10060 return mApp.getDeviceUceEnabled();
10061 } finally {
10062 Binder.restoreCallingIdentity(identity);
10063 }
10064 }
10065
10066 @Override
10067 public void setDeviceUceEnabled(boolean isEnabled) {
10068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 mApp.setDeviceUceEnabled(isEnabled);
10072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010078 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10079 String callingPackage) {
10080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10081 mApp, subId, "setSignalStrengthUpdateRequest");
10082
10083 final int callingUid = Binder.getCallingUid();
10084 // Verify that tha callingPackage belongs to the calling UID
10085 mApp.getSystemService(AppOpsManager.class)
10086 .checkPackage(callingUid, callingPackage);
10087
10088 validateSignalStrengthUpdateRequest(request, callingUid);
10089
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10093 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10094
10095 if (result instanceof IllegalStateException) {
10096 throw (IllegalStateException) result;
10097 }
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
10103 @Override
10104 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10105 String callingPackage) {
10106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10107 mApp, subId, "clearSignalStrengthUpdateRequest");
10108
10109 final int callingUid = Binder.getCallingUid();
10110 // Verify that tha callingPackage belongs to the calling UID
10111 mApp.getSystemService(AppOpsManager.class)
10112 .checkPackage(callingUid, callingPackage);
10113
10114 final long identity = Binder.clearCallingIdentity();
10115 try {
10116 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10117 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10118
10119 if (result instanceof IllegalStateException) {
10120 throw (IllegalStateException) result;
10121 }
10122 } finally {
10123 Binder.restoreCallingIdentity(identity);
10124 }
10125 }
10126
10127 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10128 int callingUid) {
10129 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10130 // phone/system process do not have further restriction on request
10131 return;
10132 }
10133
10134 // Applications has restrictions on how to use the request:
10135 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10136 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10137 // This is not system caller which has been checked above
10138 throw new IllegalArgumentException(
10139 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10140 }
10141
10142 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10143 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10144 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10145 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10146 || info.isEnabled()) {
10147 throw new IllegalArgumentException(
10148 "Only system can set hide fields in SignalThresholdInfo");
10149 }
10150
10151 // Thresholds length for each RAN need in range. This has been validated in
10152 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10153 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10154 final int[] thresholds = info.getThresholds();
10155 Objects.requireNonNull(thresholds);
10156 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10157 || thresholds.length
10158 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10159 throw new IllegalArgumentException(
10160 "thresholds length is out of range: " + thresholds.length);
10161 }
10162 }
10163 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010164
10165 /**
10166 * Gets the current phone capability.
10167 *
10168 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10169 * @return the PhoneCapability which describes the data connection capability of modem.
10170 * It's used to evaluate possible phone config change, for example from single
10171 * SIM device to multi-SIM device.
10172 */
10173 @Override
10174 public PhoneCapability getPhoneCapability() {
10175 enforceReadPrivilegedPermission("getPhoneCapability");
10176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10179 } finally {
10180 Binder.restoreCallingIdentity(identity);
10181 }
10182 }
Michele Berionne5e411512020-11-13 02:36:59 +000010183
10184 /**
10185 * Prepare TelephonyManager for an unattended reboot. The reboot is
10186 * required to be done shortly after the API is invoked.
10187 */
10188 @Override
10189 @TelephonyManager.PrepareUnattendedRebootResult
10190 public int prepareForUnattendedReboot() {
10191 enforceRebootPermission();
10192
10193 final long identity = Binder.clearCallingIdentity();
10194 try {
10195 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10196 } finally {
10197 Binder.restoreCallingIdentity(identity);
10198 }
10199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010200}