Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 25 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 27 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 34 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 35 | import android.app.role.RoleManager; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 36 | import android.compat.annotation.ChangeId; |
| 37 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 38 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 39 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 43 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 44 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.AsyncResult; |
| 48 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 49 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 52 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Looper; |
| 54 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 56 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 57 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 58 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 59 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 60 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 61 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 62 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 63 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 65 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 66 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 67 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 68 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 69 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 70 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 71 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 74 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 75 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 76 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 77 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 78 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 79 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 80 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 81 | import android.telephony.CellIdentityCdma; |
| 82 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfoGsm; |
| 85 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 86 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 87 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 88 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 89 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 90 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 91 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 92 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 94 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 95 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 97 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 100 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrengthUpdateRequest; |
| 102 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 103 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 105 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 106 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 108 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 109 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 110 | import android.telephony.UiccCardInfo; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 111 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 112 | import android.telephony.UiccSlotInfo; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 114 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 115 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 116 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 117 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 118 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 119 | import android.telephony.gba.GbaAuthRequest; |
| 120 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 121 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 123 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 125 | import android.telephony.ims.RegistrationManager; |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 126 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 133 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 135 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 139 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 140 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 142 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 143 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 144 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 145 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 146 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 147 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 162 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.IccCard; |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 167 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 178 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 191 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 192 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 207 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 208 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 209 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 210 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 211 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 212 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 213 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 214 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 217 | import com.android.services.telephony.TelecomAccountRegistry; |
| 218 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 219 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 220 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 222 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.io.IOException; |
| 224 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 225 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 227 | import java.util.Arrays; |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 228 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 229 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 230 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 231 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 232 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 233 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 234 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 235 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 236 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 237 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 238 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 239 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Implementation of the ITelephony interface. |
| 243 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 244 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 246 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 247 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 248 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 249 | |
| 250 | // Message codes used with mMainThreadHandler |
| 251 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 252 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 253 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 254 | private static final int CMD_OPEN_CHANNEL = 9; |
| 255 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 256 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 257 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 258 | private static final int CMD_NV_READ_ITEM = 13; |
| 259 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 260 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 261 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 262 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 263 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 264 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 265 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 266 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 267 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 268 | private static final int CMD_SEND_ENVELOPE = 25; |
| 269 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 270 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 271 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 272 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 273 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 274 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 275 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 276 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 277 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 278 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 279 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 280 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 281 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 282 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 283 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 284 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 285 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 286 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 287 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 288 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 289 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 290 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 291 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 292 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 293 | private static final int CMD_SWITCH_SLOTS = 50; |
| 294 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 295 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 296 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 297 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 298 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 299 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 300 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 301 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 302 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 303 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 304 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 305 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 306 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 307 | private static final int CMD_MODEM_REBOOT = 64; |
| 308 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 309 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 310 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 311 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 312 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 314 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 315 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 316 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 317 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 318 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 319 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 320 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 321 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 322 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 323 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 324 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 325 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 326 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 327 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 328 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 329 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 330 | private static final int CMD_GET_CALL_WAITING = 87; |
| 331 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 332 | private static final int CMD_SET_CALL_WAITING = 89; |
| 333 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 334 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 335 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 336 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 337 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 338 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 339 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 341 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 342 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 343 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 344 | private static final int CMD_SET_SIM_POWER = 101; |
| 345 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 346 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 347 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 348 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 349 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 350 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 351 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 352 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 353 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 354 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 355 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 356 | private static final int CMD_ENABLE_VONR = 113; |
| 357 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 358 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 359 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 361 | // Parameters of select command. |
| 362 | private static final int SELECT_COMMAND = 0xA4; |
| 363 | private static final int SELECT_P1 = 0x04; |
| 364 | private static final int SELECT_P2 = 0; |
| 365 | private static final int SELECT_P3 = 0x10; |
| 366 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | /** The singleton instance. */ |
| 368 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 369 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 371 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 372 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 373 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 374 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 375 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 376 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 378 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 379 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 380 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 381 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 383 | /** User Activity */ |
| 384 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 385 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 386 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 387 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 388 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 389 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 390 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 391 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 392 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 393 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 394 | // String to store multi SIM allowed |
| 395 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 396 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 397 | // The AID of ISD-R. |
| 398 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 399 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 400 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 401 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 402 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 403 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 404 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 405 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 406 | private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 407 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 408 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 409 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 410 | */ |
| 411 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 412 | "reset_network_erase_modem_config_enabled"; |
| 413 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 414 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 415 | /** |
| 416 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 417 | * one ICCID active at the same time. |
| 418 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 419 | * |
| 420 | * @hide |
| 421 | */ |
| 422 | @ChangeId |
| 423 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 424 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 425 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 426 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 427 | * A request object to use for transmitting data to an ICC. |
| 428 | */ |
| 429 | private static final class IccAPDUArgument { |
| 430 | public int channel, cla, command, p1, p2, p3; |
| 431 | public String data; |
| 432 | |
| 433 | public IccAPDUArgument(int channel, int cla, int command, |
| 434 | int p1, int p2, int p3, String data) { |
| 435 | this.channel = channel; |
| 436 | this.cla = cla; |
| 437 | this.command = command; |
| 438 | this.p1 = p1; |
| 439 | this.p2 = p2; |
| 440 | this.p3 = p3; |
| 441 | this.data = data; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 446 | * A request object to use for transmitting data to an ICC. |
| 447 | */ |
| 448 | private static final class ManualNetworkSelectionArgument { |
| 449 | public OperatorInfo operatorInfo; |
| 450 | public boolean persistSelection; |
| 451 | |
| 452 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 453 | this.operatorInfo = operatorInfo; |
| 454 | this.persistSelection = persistSelection; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 459 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 460 | * request after sending. The main thread will notify the request when it is complete. |
| 461 | */ |
| 462 | private static final class MainThreadRequest { |
| 463 | /** The argument to use for the request */ |
| 464 | public Object argument; |
| 465 | /** The result of the request that is run on the main thread */ |
| 466 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 467 | // The subscriber id that this request applies to. Defaults to |
| 468 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 469 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 471 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 472 | public Phone phone; |
| 473 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 474 | public WorkSource workSource; |
| 475 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | public MainThreadRequest(Object argument) { |
| 477 | this.argument = argument; |
| 478 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 479 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 480 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 481 | this.argument = argument; |
| 482 | if (phone != null) { |
| 483 | this.phone = phone; |
| 484 | } |
| 485 | this.workSource = workSource; |
| 486 | } |
| 487 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 488 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 489 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 490 | if (subId != null) { |
| 491 | this.subId = subId; |
| 492 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 493 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 494 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 497 | private static final class IncomingThirdPartyCallArgs { |
| 498 | public final ComponentName component; |
| 499 | public final String callId; |
| 500 | public final String callerDisplayName; |
| 501 | |
| 502 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 503 | String callerDisplayName) { |
| 504 | this.component = component; |
| 505 | this.callId = callId; |
| 506 | this.callerDisplayName = callerDisplayName; |
| 507 | } |
| 508 | } |
| 509 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | /** |
| 511 | * A handler that processes messages on the main thread in the phone process. Since many |
| 512 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 513 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 514 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 515 | * on, which will be notified when the operation completes and will contain the result of the |
| 516 | * request. |
| 517 | * |
| 518 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 519 | * note that request.result must be set to something non-null for the calling thread to |
| 520 | * unblock. |
| 521 | */ |
| 522 | private final class MainThreadHandler extends Handler { |
| 523 | @Override |
| 524 | public void handleMessage(Message msg) { |
| 525 | MainThreadRequest request; |
| 526 | Message onCompleted; |
| 527 | AsyncResult ar; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 528 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 529 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 530 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | |
| 532 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | case CMD_HANDLE_USSD_REQUEST: { |
| 534 | request = (MainThreadRequest) msg.obj; |
| 535 | final Phone phone = getPhoneFromRequest(request); |
| 536 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 537 | String ussdRequest = ussdObject.first; |
| 538 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 539 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 540 | if (!isUssdApiAllowed(request.subId)) { |
| 541 | // Carrier does not support use of this API, return failure. |
| 542 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 543 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 544 | Bundle returnData = new Bundle(); |
| 545 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 546 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 547 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | request.result = true; |
| 549 | notifyRequester(request); |
| 550 | return; |
| 551 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 552 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 553 | try { |
| 554 | request.result = phone != null |
| 555 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 556 | } catch (CallStateException cse) { |
| 557 | request.result = false; |
| 558 | } |
| 559 | // Wake up the requesting thread |
| 560 | notifyRequester(request); |
| 561 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 564 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 565 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 566 | final Phone phone = getPhoneFromRequest(request); |
| 567 | request.result = phone != null ? |
| 568 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 569 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 570 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 571 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 572 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 576 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 577 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 578 | uiccPort = getUiccPortFromRequest(request); |
| 579 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 580 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 583 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 585 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 586 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 588 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 590 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 591 | break; |
| 592 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 594 | ar = (AsyncResult) msg.obj; |
| 595 | request = (MainThreadRequest) ar.userObj; |
| 596 | if (ar.exception == null && ar.result != null) { |
| 597 | request.result = ar.result; |
| 598 | } else { |
| 599 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 600 | if (ar.result == null) { |
| 601 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 602 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 604 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | } else { |
| 606 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 607 | } |
| 608 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 609 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | break; |
| 611 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 613 | request = (MainThreadRequest) msg.obj; |
| 614 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 615 | uiccPort = getUiccPortFromRequest(request); |
| 616 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 618 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | } else { |
| 621 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 622 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 623 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 625 | iccArgument.p3, iccArgument.data, onCompleted); |
| 626 | } |
| 627 | break; |
| 628 | |
| 629 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 630 | ar = (AsyncResult) msg.obj; |
| 631 | request = (MainThreadRequest) ar.userObj; |
| 632 | if (ar.exception == null && ar.result != null) { |
| 633 | request.result = ar.result; |
| 634 | } else { |
| 635 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 636 | if (ar.result == null) { |
| 637 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 638 | } else if (ar.exception instanceof CommandException) { |
| 639 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 640 | ar.exception); |
| 641 | } else { |
| 642 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 643 | } |
| 644 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | break; |
| 647 | |
| 648 | case CMD_EXCHANGE_SIM_IO: |
| 649 | request = (MainThreadRequest) msg.obj; |
| 650 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 651 | uiccPort = getUiccPortFromRequest(request); |
| 652 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 653 | loge("iccExchangeSimIO: No UICC"); |
| 654 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | } else { |
| 657 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 658 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 659 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 660 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 661 | iccArgument.data, onCompleted); |
| 662 | } |
| 663 | break; |
| 664 | |
| 665 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 666 | ar = (AsyncResult) msg.obj; |
| 667 | request = (MainThreadRequest) ar.userObj; |
| 668 | if (ar.exception == null && ar.result != null) { |
| 669 | request.result = ar.result; |
| 670 | } else { |
| 671 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 672 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | break; |
| 675 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 676 | case CMD_SEND_ENVELOPE: |
| 677 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 678 | uiccPort = getUiccPortFromRequest(request); |
| 679 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 680 | loge("sendEnvelopeWithStatus: No UICC"); |
| 681 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 682 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 683 | } else { |
| 684 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 685 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_SEND_ENVELOPE_DONE: |
| 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 694 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 695 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 696 | if (ar.result == null) { |
| 697 | loge("sendEnvelopeWithStatus: Empty response"); |
| 698 | } else if (ar.exception instanceof CommandException) { |
| 699 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 700 | ar.exception); |
| 701 | } else { |
| 702 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 703 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 706 | break; |
| 707 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | case CMD_OPEN_CHANNEL: |
| 709 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 710 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 711 | IccLogicalChannelRequest openChannelRequest = |
| 712 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 713 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 714 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 715 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 716 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 718 | } else { |
| 719 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 720 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 721 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 722 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case EVENT_OPEN_CHANNEL_DONE: |
| 726 | ar = (AsyncResult) msg.obj; |
| 727 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 728 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 729 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 730 | int[] result = (int[]) ar.result; |
| 731 | int channelId = result[0]; |
| 732 | byte[] selectResponse = null; |
| 733 | if (result.length > 1) { |
| 734 | selectResponse = new byte[result.length - 1]; |
| 735 | for (int i = 1; i < result.length; ++i) { |
| 736 | selectResponse[i - 1] = (byte) result[i]; |
| 737 | } |
| 738 | } |
| 739 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 740 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | if (ar.result == null) { |
| 743 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 744 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 745 | if (ar.exception != null) { |
| 746 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 747 | } |
| 748 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 749 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 750 | if (ar.exception instanceof CommandException) { |
| 751 | CommandException.Error error = |
| 752 | ((CommandException) (ar.exception)).getCommandError(); |
| 753 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 754 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 755 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 756 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 760 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 762 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 763 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | break; |
| 765 | |
| 766 | case CMD_CLOSE_CHANNEL: |
| 767 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 768 | uiccPort = getUiccPortFromRequest(request); |
| 769 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 770 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 771 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 772 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 773 | } else { |
| 774 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 775 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 776 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 777 | break; |
| 778 | |
| 779 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 780 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 781 | break; |
| 782 | |
| 783 | case CMD_NV_READ_ITEM: |
| 784 | request = (MainThreadRequest) msg.obj; |
| 785 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 786 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 787 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | break; |
| 789 | |
| 790 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 791 | ar = (AsyncResult) msg.obj; |
| 792 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | if (ar.exception == null && ar.result != null) { |
| 794 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 795 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 796 | request.result = ""; |
| 797 | if (ar.result == null) { |
| 798 | loge("nvReadItem: Empty response"); |
| 799 | } else if (ar.exception instanceof CommandException) { |
| 800 | loge("nvReadItem: CommandException: " + |
| 801 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 802 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 803 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 806 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 807 | break; |
| 808 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 809 | case CMD_NV_WRITE_ITEM: |
| 810 | request = (MainThreadRequest) msg.obj; |
| 811 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 812 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 813 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 814 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 815 | break; |
| 816 | |
| 817 | case EVENT_NV_WRITE_ITEM_DONE: |
| 818 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 819 | break; |
| 820 | |
| 821 | case CMD_NV_WRITE_CDMA_PRL: |
| 822 | request = (MainThreadRequest) msg.obj; |
| 823 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 824 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 825 | break; |
| 826 | |
| 827 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 828 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 829 | break; |
| 830 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 831 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 832 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 833 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 834 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 835 | break; |
| 836 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 837 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 838 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 839 | break; |
| 840 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 841 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 842 | request = (MainThreadRequest) msg.obj; |
| 843 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 844 | request); |
| 845 | Phone phone = getPhoneFromRequest(request); |
| 846 | if (phone != null) { |
| 847 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 848 | } else { |
| 849 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 850 | request.result = false; |
| 851 | notifyRequester(request); |
| 852 | } |
| 853 | break; |
| 854 | } |
| 855 | |
| 856 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 857 | ar = (AsyncResult) msg.obj; |
| 858 | request = (MainThreadRequest) ar.userObj; |
| 859 | if (ar.exception == null && ar.result != null) { |
| 860 | request.result = ar.result; |
| 861 | } else { |
| 862 | // request.result must be set to something non-null |
| 863 | // for the calling thread to unblock |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 864 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 865 | request.result = ar.result; |
| 866 | } else { |
| 867 | request.result = false; |
| 868 | } |
| 869 | if (ar.result == null) { |
| 870 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 871 | } else if (ar.exception instanceof CommandException) { |
| 872 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 873 | + ar.exception); |
| 874 | } else { |
| 875 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 876 | } |
| 877 | } |
| 878 | notifyRequester(request); |
| 879 | break; |
| 880 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 881 | case CMD_IS_VONR_ENABLED: { |
| 882 | request = (MainThreadRequest) msg.obj; |
| 883 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 884 | request); |
| 885 | Phone phone = getPhoneFromRequest(request); |
| 886 | if (phone != null) { |
| 887 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 888 | } else { |
| 889 | loge("isVoNrEnabled: No phone object"); |
| 890 | request.result = false; |
| 891 | notifyRequester(request); |
| 892 | } |
| 893 | break; |
| 894 | } |
| 895 | |
| 896 | case EVENT_IS_VONR_ENABLED_DONE: |
| 897 | ar = (AsyncResult) msg.obj; |
| 898 | request = (MainThreadRequest) ar.userObj; |
| 899 | if (ar.exception == null && ar.result != null) { |
| 900 | request.result = ar.result; |
| 901 | } else { |
| 902 | // request.result must be set to something non-null |
| 903 | // for the calling thread to unblock |
| 904 | if (ar.result != null) { |
| 905 | request.result = ar.result; |
| 906 | } else { |
| 907 | request.result = false; |
| 908 | } |
| 909 | if (ar.result == null) { |
| 910 | loge("isVoNrEnabled: Empty response"); |
| 911 | } else if (ar.exception instanceof CommandException) { |
| 912 | loge("isVoNrEnabled: CommandException: " |
| 913 | + ar.exception); |
| 914 | } else { |
| 915 | loge("isVoNrEnabled: Unknown exception"); |
| 916 | } |
| 917 | } |
| 918 | notifyRequester(request); |
| 919 | break; |
| 920 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 921 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 922 | request = (MainThreadRequest) msg.obj; |
| 923 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 924 | Phone phone = getPhoneFromRequest(request); |
| 925 | if (phone != null) { |
| 926 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 927 | request.workSource); |
| 928 | } else { |
| 929 | loge("enableNrDualConnectivity: No phone object"); |
| 930 | request.result = |
| 931 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 932 | notifyRequester(request); |
| 933 | } |
| 934 | break; |
| 935 | } |
| 936 | |
| 937 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 938 | ar = (AsyncResult) msg.obj; |
| 939 | request = (MainThreadRequest) ar.userObj; |
| 940 | if (ar.exception == null) { |
| 941 | request.result = |
| 942 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 943 | } else { |
| 944 | request.result = |
| 945 | TelephonyManager |
| 946 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 947 | if (ar.exception instanceof CommandException) { |
| 948 | CommandException.Error error = |
| 949 | ((CommandException) (ar.exception)).getCommandError(); |
| 950 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 951 | request.result = |
| 952 | TelephonyManager |
| 953 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 954 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 955 | request.result = |
| 956 | TelephonyManager |
| 957 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 958 | } |
| 959 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 960 | + ar.exception); |
| 961 | } else { |
| 962 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 963 | } |
| 964 | } |
| 965 | notifyRequester(request); |
| 966 | break; |
| 967 | } |
| 968 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 969 | case CMD_ENABLE_VONR: { |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 972 | Phone phone = getPhoneFromRequest(request); |
| 973 | if (phone != null) { |
| 974 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 975 | request.workSource); |
| 976 | } else { |
| 977 | loge("setVoNrEnabled: No phone object"); |
| 978 | request.result = |
| 979 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 980 | notifyRequester(request); |
| 981 | } |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | case EVENT_ENABLE_VONR_DONE: { |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | if (ar.exception == null) { |
| 989 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 990 | } else { |
| 991 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 992 | if (ar.exception instanceof CommandException) { |
| 993 | CommandException.Error error = |
| 994 | ((CommandException) (ar.exception)).getCommandError(); |
| 995 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 996 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 997 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 998 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 999 | } else { |
| 1000 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1001 | } |
| 1002 | loge("setVoNrEnabled" + ": CommandException: " |
| 1003 | + ar.exception); |
| 1004 | } else { |
| 1005 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1006 | } |
| 1007 | } |
| 1008 | notifyRequester(request); |
| 1009 | break; |
| 1010 | } |
| 1011 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1012 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1013 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1014 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1015 | request); |
| 1016 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1017 | break; |
| 1018 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1019 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1020 | ar = (AsyncResult) msg.obj; |
| 1021 | request = (MainThreadRequest) ar.userObj; |
| 1022 | if (ar.exception == null && ar.result != null) { |
| 1023 | request.result = ar.result; // Integer |
| 1024 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1025 | // request.result must be set to something non-null |
| 1026 | // for the calling thread to unblock |
| 1027 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1028 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1029 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1030 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1031 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1032 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1033 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1034 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1035 | } |
| 1036 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1037 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1038 | break; |
| 1039 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1040 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1041 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1042 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1043 | request); |
| 1044 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1045 | (Pair<Integer, Long>) request.argument; |
| 1046 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1047 | reasonWithNetworkTypes.first, |
| 1048 | reasonWithNetworkTypes.second, |
| 1049 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1050 | break; |
| 1051 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1052 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1053 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1054 | break; |
| 1055 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1056 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1057 | request = (MainThreadRequest)msg.obj; |
| 1058 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1059 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | |
| 1062 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1063 | ar = (AsyncResult)msg.obj; |
| 1064 | request = (MainThreadRequest)ar.userObj; |
| 1065 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1066 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1067 | break; |
| 1068 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1069 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1070 | request = (MainThreadRequest) msg.obj; |
| 1071 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1072 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1073 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1074 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1075 | break; |
| 1076 | |
| 1077 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1078 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1079 | break; |
| 1080 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1081 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1082 | request = (MainThreadRequest) msg.obj; |
| 1083 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1084 | request); |
| 1085 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1086 | break; |
| 1087 | |
| 1088 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1089 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1090 | break; |
| 1091 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1092 | case CMD_PERFORM_NETWORK_SCAN: |
| 1093 | request = (MainThreadRequest) msg.obj; |
| 1094 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1095 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1096 | break; |
| 1097 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1099 | request = (MainThreadRequest) msg.obj; |
| 1100 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1102 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1103 | request.argument; |
| 1104 | int callForwardingReason = args.first; |
| 1105 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1106 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | } |
| 1108 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1109 | ar = (AsyncResult) msg.obj; |
| 1110 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1112 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1113 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1114 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1116 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1117 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1118 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1119 | // any service for voice call. |
| 1120 | if ((callForwardInfo.serviceClass |
| 1121 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1122 | callForwardingInfo = new CallForwardingInfo( |
| 1123 | callForwardInfo.status |
| 1124 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1125 | callForwardInfo.reason, |
| 1126 | callForwardInfo.number, |
| 1127 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1128 | break; |
| 1129 | } |
| 1130 | } |
| 1131 | // Didn't find a call forward info for voice call. |
| 1132 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1134 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1135 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1136 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1137 | } else { |
| 1138 | if (ar.result == null) { |
| 1139 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1140 | } |
| 1141 | if (ar.exception != null) { |
| 1142 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1143 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1144 | int errorCode = TelephonyManager |
| 1145 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1146 | if (ar.exception instanceof CommandException) { |
| 1147 | CommandException.Error error = |
| 1148 | ((CommandException) (ar.exception)).getCommandError(); |
| 1149 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1150 | errorCode = TelephonyManager |
| 1151 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1153 | errorCode = TelephonyManager |
| 1154 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | } |
| 1156 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1157 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1159 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1160 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1161 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1162 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1163 | request = (MainThreadRequest) msg.obj; |
| 1164 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1165 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1166 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1167 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1168 | request.argument).first; |
| 1169 | request.phone.setCallForwardingOption( |
| 1170 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1171 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1172 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1173 | callForwardingInfoToSet.getReason(), |
| 1174 | callForwardingInfoToSet.getNumber(), |
| 1175 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1176 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1177 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1178 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1179 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1180 | ar = (AsyncResult) msg.obj; |
| 1181 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1182 | Consumer<Integer> callback = |
| 1183 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1184 | request.argument).second; |
| 1185 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1186 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1187 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1188 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1189 | if (ar.exception instanceof CommandException) { |
| 1190 | CommandException.Error error = |
| 1191 | ((CommandException) (ar.exception)).getCommandError(); |
| 1192 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1193 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1194 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1195 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1196 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1197 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | callback.accept(errorCode); |
| 1201 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1202 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1205 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1206 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1207 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | request = (MainThreadRequest) msg.obj; |
| 1209 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1210 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1211 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1215 | ar = (AsyncResult) msg.obj; |
| 1216 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1219 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1220 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | // Service Class is a bit mask per 3gpp 27.007. |
| 1222 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1223 | if (callForwardResults.length > 1 |
| 1224 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1226 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1228 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1229 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1230 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | } |
| 1232 | } else { |
| 1233 | if (ar.result == null) { |
| 1234 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1235 | } |
| 1236 | if (ar.exception != null) { |
| 1237 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1238 | } |
| 1239 | if (ar.exception instanceof CommandException) { |
| 1240 | CommandException.Error error = |
| 1241 | ((CommandException) (ar.exception)).getCommandError(); |
| 1242 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1243 | callForwardingStatus = |
| 1244 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1245 | } |
| 1246 | } |
| 1247 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | request = (MainThreadRequest) msg.obj; |
| 1254 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1256 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | ar = (AsyncResult) msg.obj; |
| 1262 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1264 | Consumer<Integer> callback = |
| 1265 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1266 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | if (ar.exception instanceof CommandException) { |
| 1269 | CommandException.Error error = |
| 1270 | ((CommandException) (ar.exception)).getCommandError(); |
| 1271 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1272 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1273 | } else { |
| 1274 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1275 | } |
| 1276 | } else { |
| 1277 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1278 | } |
| 1279 | } else { |
| 1280 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1281 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1285 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1286 | ar = (AsyncResult) msg.obj; |
| 1287 | request = (MainThreadRequest) ar.userObj; |
| 1288 | CellNetworkScanResult cellScanResult; |
| 1289 | if (ar.exception == null && ar.result != null) { |
| 1290 | cellScanResult = new CellNetworkScanResult( |
| 1291 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1292 | (List<OperatorInfo>) ar.result); |
| 1293 | } else { |
| 1294 | if (ar.result == null) { |
| 1295 | loge("getCellNetworkScanResults: Empty response"); |
| 1296 | } |
| 1297 | if (ar.exception != null) { |
| 1298 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1299 | } |
| 1300 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1301 | if (ar.exception instanceof CommandException) { |
| 1302 | CommandException.Error error = |
| 1303 | ((CommandException) (ar.exception)).getCommandError(); |
| 1304 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1305 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1306 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1307 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1308 | } |
| 1309 | } |
| 1310 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1311 | } |
| 1312 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1313 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | |
| 1316 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1317 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1318 | ManualNetworkSelectionArgument selArg = |
| 1319 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1320 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1321 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1322 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1323 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1324 | break; |
| 1325 | |
| 1326 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1327 | ar = (AsyncResult) msg.obj; |
| 1328 | request = (MainThreadRequest) ar.userObj; |
| 1329 | if (ar.exception == null) { |
| 1330 | request.result = true; |
| 1331 | } else { |
| 1332 | request.result = false; |
| 1333 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1334 | } |
| 1335 | notifyRequester(request); |
| 1336 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1337 | break; |
| 1338 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1339 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1340 | request = (MainThreadRequest) msg.obj; |
| 1341 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1342 | if (defaultPhone != null) { |
| 1343 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1344 | } else { |
| 1345 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1346 | Bundle bundle = new Bundle(); |
| 1347 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1348 | new ModemActivityInfo(0, 0, 0, |
| 1349 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1350 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1351 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1352 | break; |
| 1353 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1354 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1355 | ar = (AsyncResult) msg.obj; |
| 1356 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1357 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1358 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1359 | ModemActivityInfo ret = null; |
| 1360 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1361 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1362 | // Update the last modem activity info and the result of the request. |
| 1363 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1364 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1365 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1366 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1367 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1368 | .getTransmitTimeMillis(); |
| 1369 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1370 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1371 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1372 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1373 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1374 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1375 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1376 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1377 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1378 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1379 | info.getReceiveTimeMillis() |
| 1380 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1381 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1382 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1383 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1384 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1385 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1386 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1387 | } else { |
| 1388 | if (ar.result == null) { |
| 1389 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1390 | error = TelephonyManager.ModemActivityInfoException |
| 1391 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1392 | } else if (ar.exception instanceof CommandException) { |
| 1393 | loge("queryModemActivityInfo: CommandException: " + |
| 1394 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1395 | error = TelephonyManager.ModemActivityInfoException |
| 1396 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1397 | } else { |
| 1398 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1399 | error = TelephonyManager.ModemActivityInfoException |
| 1400 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1403 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1404 | if (ret != null) { |
| 1405 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1406 | } else { |
| 1407 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1408 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1409 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1410 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1411 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1412 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1413 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1414 | case CMD_SET_ALLOWED_CARRIERS: |
| 1415 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1416 | CarrierRestrictionRules argument = |
| 1417 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1418 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1419 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | |
| 1422 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1423 | ar = (AsyncResult) msg.obj; |
| 1424 | request = (MainThreadRequest) ar.userObj; |
| 1425 | if (ar.exception == null && ar.result != null) { |
| 1426 | request.result = ar.result; |
| 1427 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1428 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1429 | if (ar.exception instanceof CommandException) { |
| 1430 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1431 | CommandException.Error error = |
| 1432 | ((CommandException) (ar.exception)).getCommandError(); |
| 1433 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1434 | request.result = |
| 1435 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1436 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1437 | } else { |
| 1438 | loge("setAllowedCarriers: Unknown exception"); |
| 1439 | } |
| 1440 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1441 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1442 | break; |
| 1443 | |
| 1444 | case CMD_GET_ALLOWED_CARRIERS: |
| 1445 | request = (MainThreadRequest) msg.obj; |
| 1446 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1447 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | |
| 1450 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1451 | ar = (AsyncResult) msg.obj; |
| 1452 | request = (MainThreadRequest) ar.userObj; |
| 1453 | if (ar.exception == null && ar.result != null) { |
| 1454 | request.result = ar.result; |
| 1455 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1456 | request.result = new IllegalStateException( |
| 1457 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1458 | if (ar.result == null) { |
| 1459 | loge("getAllowedCarriers: Empty response"); |
| 1460 | } else if (ar.exception instanceof CommandException) { |
| 1461 | loge("getAllowedCarriers: CommandException: " + |
| 1462 | ar.exception); |
| 1463 | } else { |
| 1464 | loge("getAllowedCarriers: Unknown exception"); |
| 1465 | } |
| 1466 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1467 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1468 | break; |
| 1469 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1470 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1471 | ar = (AsyncResult) msg.obj; |
| 1472 | request = (MainThreadRequest) ar.userObj; |
| 1473 | if (ar.exception == null && ar.result != null) { |
| 1474 | request.result = ar.result; |
| 1475 | } else { |
| 1476 | request.result = new IllegalArgumentException( |
| 1477 | "Failed to retrieve Forbidden Plmns"); |
| 1478 | if (ar.result == null) { |
| 1479 | loge("getForbiddenPlmns: Empty response"); |
| 1480 | } else { |
| 1481 | loge("getForbiddenPlmns: Unknown exception"); |
| 1482 | } |
| 1483 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1484 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1485 | break; |
| 1486 | |
| 1487 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1488 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1489 | uiccPort = getUiccPortFromRequest(request); |
| 1490 | if (uiccPort == null) { |
| 1491 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1492 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1493 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1494 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1495 | break; |
| 1496 | } |
| 1497 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1498 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1499 | if (uiccApp == null) { |
| 1500 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1501 | + appType); |
| 1502 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1503 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1504 | break; |
| 1505 | } else { |
| 1506 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1507 | + " specified type -- " + appType); |
| 1508 | } |
| 1509 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1510 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1511 | onCompleted); |
| 1512 | break; |
| 1513 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1514 | case CMD_SWITCH_SLOTS: |
| 1515 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1516 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1517 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1518 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1519 | break; |
| 1520 | |
| 1521 | case EVENT_SWITCH_SLOTS_DONE: |
| 1522 | ar = (AsyncResult) msg.obj; |
| 1523 | request = (MainThreadRequest) ar.userObj; |
| 1524 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1525 | notifyRequester(request); |
| 1526 | break; |
| 1527 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1528 | request = (MainThreadRequest) msg.obj; |
| 1529 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1530 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1531 | break; |
| 1532 | |
| 1533 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1534 | ar = (AsyncResult) msg.obj; |
| 1535 | request = (MainThreadRequest) ar.userObj; |
| 1536 | if (ar.exception != null) { |
| 1537 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1538 | } else { |
| 1539 | int mode = ((int[]) ar.result)[0]; |
| 1540 | if (mode == 0) { |
| 1541 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1542 | } else { |
| 1543 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1544 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1545 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1546 | notifyRequester(request); |
| 1547 | break; |
| 1548 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1549 | request = (MainThreadRequest) msg.obj; |
| 1550 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1551 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1552 | break; |
| 1553 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1554 | ar = (AsyncResult) msg.obj; |
| 1555 | request = (MainThreadRequest) ar.userObj; |
| 1556 | if (ar.exception != null) { |
| 1557 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1558 | } else { |
| 1559 | request.result = ((int[]) ar.result)[0]; |
| 1560 | } |
| 1561 | notifyRequester(request); |
| 1562 | break; |
| 1563 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1564 | request = (MainThreadRequest) msg.obj; |
| 1565 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1566 | int mode = (int) request.argument; |
| 1567 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1568 | break; |
| 1569 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1570 | ar = (AsyncResult) msg.obj; |
| 1571 | request = (MainThreadRequest) ar.userObj; |
| 1572 | request.result = ar.exception == null; |
| 1573 | notifyRequester(request); |
| 1574 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1575 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1576 | request = (MainThreadRequest) msg.obj; |
| 1577 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1578 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1579 | break; |
| 1580 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1581 | ar = (AsyncResult) msg.obj; |
| 1582 | request = (MainThreadRequest) ar.userObj; |
| 1583 | if (ar.exception != null) { |
| 1584 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1585 | } else { |
| 1586 | request.result = ((int[]) ar.result)[0]; |
| 1587 | } |
| 1588 | notifyRequester(request); |
| 1589 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1590 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1591 | request = (MainThreadRequest) msg.obj; |
| 1592 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1593 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1594 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1595 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1598 | ar = (AsyncResult) msg.obj; |
| 1599 | request = (MainThreadRequest) ar.userObj; |
| 1600 | request.result = ar.exception == null; |
| 1601 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1602 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1603 | case CMD_GET_ALL_CELL_INFO: |
| 1604 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1605 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1606 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1607 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1608 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1609 | ar = (AsyncResult) msg.obj; |
| 1610 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1611 | // If a timeout occurs, the response will be null |
| 1612 | request.result = (ar.exception == null && ar.result != null) |
| 1613 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1614 | synchronized (request) { |
| 1615 | request.notifyAll(); |
| 1616 | } |
| 1617 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1618 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1619 | request = (MainThreadRequest) msg.obj; |
| 1620 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1621 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1622 | break; |
| 1623 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1624 | ar = (AsyncResult) msg.obj; |
| 1625 | request = (MainThreadRequest) ar.userObj; |
| 1626 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1627 | try { |
| 1628 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1629 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1630 | cb.onError( |
| 1631 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1632 | ar.exception.getClass().getName(), |
| 1633 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1634 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1635 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1636 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1637 | } else { |
| 1638 | // use the result as returned |
| 1639 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1640 | } |
| 1641 | } catch (RemoteException re) { |
| 1642 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1643 | } |
| 1644 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1645 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1646 | request = (MainThreadRequest) msg.obj; |
| 1647 | WorkSource ws = (WorkSource) request.argument; |
| 1648 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1649 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1650 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1651 | } |
| 1652 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1653 | ar = (AsyncResult) msg.obj; |
| 1654 | request = (MainThreadRequest) ar.userObj; |
| 1655 | if (ar.exception == null) { |
| 1656 | request.result = ar.result; |
| 1657 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1658 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1659 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1660 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | synchronized (request) { |
| 1664 | request.notifyAll(); |
| 1665 | } |
| 1666 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1667 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1668 | case CMD_MODEM_REBOOT: |
| 1669 | request = (MainThreadRequest) msg.obj; |
| 1670 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1671 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1672 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1673 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1674 | handleNullReturnEvent(msg, "rebootModem"); |
| 1675 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1676 | case CMD_REQUEST_ENABLE_MODEM: |
| 1677 | request = (MainThreadRequest) msg.obj; |
| 1678 | boolean enable = (boolean) request.argument; |
| 1679 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1680 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1681 | PhoneConfigurationManager.getInstance() |
| 1682 | .enablePhone(request.phone, enable, onCompleted); |
| 1683 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1684 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1685 | ar = (AsyncResult) msg.obj; |
| 1686 | request = (MainThreadRequest) ar.userObj; |
| 1687 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1688 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1689 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1690 | if ((boolean) request.result) { |
| 1691 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1692 | updateModemStateMetrics(); |
| 1693 | } else { |
| 1694 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1695 | + ar.exception); |
| 1696 | } |
| 1697 | notifyRequester(request); |
| 1698 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1699 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1700 | case CMD_GET_MODEM_STATUS: |
| 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1703 | PhoneConfigurationManager.getInstance() |
| 1704 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1705 | break; |
| 1706 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1707 | ar = (AsyncResult) msg.obj; |
| 1708 | request = (MainThreadRequest) ar.userObj; |
| 1709 | int id = request.phone.getPhoneId(); |
| 1710 | if (ar.exception == null && ar.result != null) { |
| 1711 | request.result = ar.result; |
| 1712 | //update the cache as modem status has changed |
| 1713 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1714 | (boolean) request.result); |
| 1715 | } else { |
| 1716 | // Return true if modem status cannot be retrieved. For most cases, |
| 1717 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1718 | // and disable modem are not supported. Modem is always on. |
| 1719 | // TODO: this should be fixed in R to support a third |
| 1720 | // status UNKNOWN b/131631629 |
| 1721 | request.result = true; |
| 1722 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1723 | + ar.exception); |
| 1724 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1725 | notifyRequester(request); |
| 1726 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1727 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1728 | request = (MainThreadRequest) msg.obj; |
| 1729 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1730 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1731 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1732 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1733 | break; |
| 1734 | } |
| 1735 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1736 | ar = (AsyncResult) msg.obj; |
| 1737 | request = (MainThreadRequest) ar.userObj; |
| 1738 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1739 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1740 | args.second.accept(ar.exception == null); |
| 1741 | notifyRequester(request); |
| 1742 | break; |
| 1743 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1744 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1745 | request = (MainThreadRequest) msg.obj; |
| 1746 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1747 | Phone phone = getPhoneFromRequest(request); |
| 1748 | if (phone != null) { |
| 1749 | phone.getSystemSelectionChannels(onCompleted); |
| 1750 | } else { |
| 1751 | loge("getSystemSelectionChannels: No phone object"); |
| 1752 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1753 | notifyRequester(request); |
| 1754 | } |
| 1755 | break; |
| 1756 | } |
| 1757 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1758 | ar = (AsyncResult) msg.obj; |
| 1759 | request = (MainThreadRequest) ar.userObj; |
| 1760 | if (ar.exception == null && ar.result != null) { |
| 1761 | request.result = ar.result; |
| 1762 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1763 | request.result = new IllegalStateException( |
| 1764 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1765 | if (ar.result == null) { |
| 1766 | loge("getSystemSelectionChannels: Empty response"); |
| 1767 | } else { |
| 1768 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1769 | } |
| 1770 | } |
| 1771 | notifyRequester(request); |
| 1772 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1773 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1774 | ar = (AsyncResult) msg.obj; |
| 1775 | request = (MainThreadRequest) ar.userObj; |
| 1776 | if (ar.exception == null && ar.result != null) { |
| 1777 | request.result = ar.result; |
| 1778 | } else { |
| 1779 | request.result = -1; |
| 1780 | loge("Failed to set Forbidden Plmns"); |
| 1781 | if (ar.result == null) { |
| 1782 | loge("setForbidenPlmns: Empty response"); |
| 1783 | } else if (ar.exception != null) { |
| 1784 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1785 | request.result = -1; |
| 1786 | } else { |
| 1787 | loge("setForbiddenPlmns: Unknown exception"); |
| 1788 | } |
| 1789 | } |
| 1790 | notifyRequester(request); |
| 1791 | break; |
| 1792 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1793 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1794 | uiccPort = getUiccPortFromRequest(request); |
| 1795 | if (uiccPort == null) { |
| 1796 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1797 | request.result = -1; |
| 1798 | notifyRequester(request); |
| 1799 | break; |
| 1800 | } |
| 1801 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1802 | (Pair<Integer, List<String>>) request.argument; |
| 1803 | appType = setFplmnsArgs.first; |
| 1804 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1805 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1806 | if (uiccApp == null) { |
| 1807 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1808 | request.result = -1; |
| 1809 | loge("Failed to get UICC App"); |
| 1810 | notifyRequester(request); |
| 1811 | } else { |
| 1812 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1813 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1814 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1815 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1816 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1817 | case CMD_ERASE_MODEM_CONFIG: |
| 1818 | request = (MainThreadRequest) msg.obj; |
| 1819 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1820 | defaultPhone.eraseModemConfig(onCompleted); |
| 1821 | break; |
| 1822 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1823 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1824 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1825 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1826 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1827 | request = (MainThreadRequest) msg.obj; |
| 1828 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1829 | notifyRequester(request); |
| 1830 | break; |
| 1831 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1832 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1833 | request = (MainThreadRequest) msg.obj; |
| 1834 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1835 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1836 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1837 | changed.first, changed.second, onCompleted); |
| 1838 | break; |
| 1839 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1840 | ar = (AsyncResult) msg.obj; |
| 1841 | request = (MainThreadRequest) ar.userObj; |
| 1842 | if (ar.exception == null) { |
| 1843 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1844 | // If the operation is successful, update the PIN storage |
| 1845 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1846 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1847 | UiccController.getInstance().getPinStorage() |
| 1848 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1849 | } else { |
| 1850 | request.result = msg.arg1; |
| 1851 | } |
| 1852 | notifyRequester(request); |
| 1853 | break; |
| 1854 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1855 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1856 | request = (MainThreadRequest) msg.obj; |
| 1857 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1858 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1859 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1860 | enabled.first, enabled.second, onCompleted); |
| 1861 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1862 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1863 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1864 | ar = (AsyncResult) msg.obj; |
| 1865 | request = (MainThreadRequest) ar.userObj; |
| 1866 | if (ar.exception == null) { |
| 1867 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1868 | // If the operation is successful, update the PIN storage |
| 1869 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1870 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1871 | if (enabled.first) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1872 | UiccController.getInstance().getPinStorage() |
| 1873 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1874 | } else { |
| 1875 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1876 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1877 | } else { |
| 1878 | request.result = msg.arg1; |
| 1879 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1880 | |
| 1881 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1882 | notifyRequester(request); |
| 1883 | break; |
| 1884 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1885 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1886 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1887 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1888 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1889 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1890 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1891 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1892 | |
| 1893 | case CMD_SET_DATA_THROTTLING: { |
| 1894 | request = (MainThreadRequest) msg.obj; |
| 1895 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1896 | DataThrottlingRequest dataThrottlingRequest = |
| 1897 | (DataThrottlingRequest) request.argument; |
| 1898 | Phone phone = getPhoneFromRequest(request); |
| 1899 | if (phone != null) { |
| 1900 | phone.setDataThrottling(onCompleted, |
| 1901 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1902 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1903 | } else { |
| 1904 | loge("setDataThrottling: No phone object"); |
| 1905 | request.result = |
| 1906 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1907 | notifyRequester(request); |
| 1908 | } |
| 1909 | |
| 1910 | break; |
| 1911 | } |
| 1912 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1913 | ar = (AsyncResult) msg.obj; |
| 1914 | request = (MainThreadRequest) ar.userObj; |
| 1915 | |
| 1916 | if (ar.exception == null) { |
| 1917 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1918 | } else if (ar.exception instanceof CommandException) { |
| 1919 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1920 | CommandException.Error error = |
| 1921 | ((CommandException) (ar.exception)).getCommandError(); |
| 1922 | |
| 1923 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1924 | request.result = TelephonyManager |
| 1925 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1926 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1927 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1928 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1929 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1930 | } else { |
| 1931 | request.result = |
| 1932 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1933 | } |
| 1934 | } else { |
| 1935 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1936 | } |
| 1937 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1938 | notifyRequester(request); |
| 1939 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1940 | |
| 1941 | case CMD_SET_SIM_POWER: { |
| 1942 | request = (MainThreadRequest) msg.obj; |
| 1943 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1944 | request = (MainThreadRequest) msg.obj; |
| 1945 | int stateToSet = |
| 1946 | ((Pair<Integer, IIntegerConsumer>) |
| 1947 | request.argument).first; |
| 1948 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1949 | break; |
| 1950 | } |
| 1951 | case EVENT_SET_SIM_POWER_DONE: { |
| 1952 | ar = (AsyncResult) msg.obj; |
| 1953 | request = (MainThreadRequest) ar.userObj; |
| 1954 | IIntegerConsumer callback = |
| 1955 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1956 | if (ar.exception != null) { |
| 1957 | loge("setSimPower exception: " + ar.exception); |
| 1958 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1959 | .RESULT_ERROR_UNKNOWN; |
| 1960 | if (ar.exception instanceof CommandException) { |
| 1961 | CommandException.Error error = |
| 1962 | ((CommandException) (ar.exception)).getCommandError(); |
| 1963 | if (error == CommandException.Error.SIM_ERR) { |
| 1964 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1965 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1966 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1967 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1968 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1969 | } else { |
| 1970 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1971 | } |
| 1972 | } |
| 1973 | try { |
| 1974 | callback.accept(errorCode); |
| 1975 | } catch (RemoteException e) { |
| 1976 | // Ignore if the remote process is no longer available to call back. |
| 1977 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1978 | } |
| 1979 | } else { |
| 1980 | try { |
| 1981 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1982 | } catch (RemoteException e) { |
| 1983 | // Ignore if the remote process is no longer available to call back. |
| 1984 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1985 | } |
| 1986 | } |
| 1987 | break; |
| 1988 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1989 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1990 | request = (MainThreadRequest) msg.obj; |
| 1991 | |
| 1992 | final Phone phone = getPhoneFromRequest(request); |
| 1993 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1994 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1995 | notifyRequester(request); |
| 1996 | break; |
| 1997 | } |
| 1998 | |
| 1999 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2000 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2001 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2002 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2003 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2004 | request.subId, pair.first /*callingUid*/, |
| 2005 | pair.second /*request*/, onCompleted); |
| 2006 | break; |
| 2007 | } |
| 2008 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2009 | ar = (AsyncResult) msg.obj; |
| 2010 | request = (MainThreadRequest) ar.userObj; |
| 2011 | // request.result will be the exception of ar if present, true otherwise. |
| 2012 | // Be cautious not to leave result null which will wait() forever |
| 2013 | request.result = ar.exception != null ? ar.exception : true; |
| 2014 | notifyRequester(request); |
| 2015 | break; |
| 2016 | } |
| 2017 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2018 | request = (MainThreadRequest) msg.obj; |
| 2019 | |
| 2020 | Phone phone = getPhoneFromRequest(request); |
| 2021 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2022 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2023 | notifyRequester(request); |
| 2024 | break; |
| 2025 | } |
| 2026 | |
| 2027 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2028 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2029 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2030 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2031 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2032 | request.subId, pair.first /*callingUid*/, |
| 2033 | pair.second /*request*/, onCompleted); |
| 2034 | break; |
| 2035 | } |
| 2036 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2037 | ar = (AsyncResult) msg.obj; |
| 2038 | request = (MainThreadRequest) ar.userObj; |
| 2039 | request.result = ar.exception != null ? ar.exception : true; |
| 2040 | notifyRequester(request); |
| 2041 | break; |
| 2042 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2043 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2044 | case CMD_GET_SLICING_CONFIG: { |
| 2045 | request = (MainThreadRequest) msg.obj; |
| 2046 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2047 | request.phone.getSlicingConfig(onCompleted); |
| 2048 | break; |
| 2049 | } |
| 2050 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2051 | ar = (AsyncResult) msg.obj; |
| 2052 | request = (MainThreadRequest) ar.userObj; |
| 2053 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2054 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2055 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2056 | Bundle bundle = new Bundle(); |
| 2057 | int resultCode = 0; |
| 2058 | if (ar.exception != null) { |
| 2059 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2060 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2061 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2062 | } else if (ar.result == null) { |
| 2063 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2064 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2065 | } else { |
| 2066 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2067 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2068 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2072 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2073 | } |
| 2074 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2075 | result.send(resultCode, bundle); |
| 2076 | notifyRequester(request); |
| 2077 | break; |
| 2078 | } |
| 2079 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2080 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2081 | request = (MainThreadRequest) msg.obj; |
| 2082 | request.result = |
| 2083 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 2084 | notifyRequester(request); |
| 2085 | break; |
| 2086 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | default: |
| 2088 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2089 | break; |
| 2090 | } |
| 2091 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2092 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2093 | private void notifyRequester(MainThreadRequest request) { |
| 2094 | synchronized (request) { |
| 2095 | request.notifyAll(); |
| 2096 | } |
| 2097 | } |
| 2098 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2099 | private void handleNullReturnEvent(Message msg, String command) { |
| 2100 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2101 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2102 | if (ar.exception == null) { |
| 2103 | request.result = true; |
| 2104 | } else { |
| 2105 | request.result = false; |
| 2106 | if (ar.exception instanceof CommandException) { |
| 2107 | loge(command + ": CommandException: " + ar.exception); |
| 2108 | } else { |
| 2109 | loge(command + ": Unknown exception"); |
| 2110 | } |
| 2111 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2112 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | /** |
| 2117 | * Posts the specified command to be executed on the main thread, |
| 2118 | * waits for the request to complete, and returns the result. |
| 2119 | * @see #sendRequestAsync |
| 2120 | */ |
| 2121 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2122 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2123 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * Posts the specified command to be executed on the main thread, |
| 2128 | * waits for the request to complete, and returns the result. |
| 2129 | * @see #sendRequestAsync |
| 2130 | */ |
| 2131 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2132 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2133 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * Posts the specified command to be executed on the main thread, |
| 2138 | * waits for the request to complete, and returns the result. |
| 2139 | * @see #sendRequestAsync |
| 2140 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2141 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2142 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * Posts the specified command to be executed on the main thread, |
| 2147 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2148 | * if not timeout or null otherwise. |
| 2149 | * @see #sendRequestAsync |
| 2150 | */ |
| 2151 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2152 | long timeoutInMs) { |
| 2153 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | /** |
| 2157 | * Posts the specified command to be executed on the main thread, |
| 2158 | * waits for the request to complete, and returns the result. |
| 2159 | * @see #sendRequestAsync |
| 2160 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2161 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2162 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | /** |
| 2166 | * Posts the specified command to be executed on the main thread, |
| 2167 | * waits for the request to complete, and returns the result. |
| 2168 | * @see #sendRequestAsync |
| 2169 | */ |
| 2170 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2171 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2172 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2176 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2177 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2178 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2179 | * @see #sendRequestAsync |
| 2180 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2181 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2182 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2183 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2184 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2185 | } |
| 2186 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2187 | MainThreadRequest request = null; |
| 2188 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2189 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2190 | } else if (phone != null) { |
| 2191 | request = new MainThreadRequest(argument, phone, workSource); |
| 2192 | } else { |
| 2193 | request = new MainThreadRequest(argument, subId, workSource); |
| 2194 | } |
| 2195 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2196 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2197 | msg.sendToTarget(); |
| 2198 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2199 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2200 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2201 | if (timeoutInMs >= 0) { |
| 2202 | // Wait for at least timeoutInMs before returning null request result |
| 2203 | long now = SystemClock.elapsedRealtime(); |
| 2204 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2205 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2206 | try { |
| 2207 | request.wait(deadline - now); |
| 2208 | } catch (InterruptedException e) { |
| 2209 | // Do nothing, go back and check if request is completed or timeout |
| 2210 | } finally { |
| 2211 | now = SystemClock.elapsedRealtime(); |
| 2212 | } |
| 2213 | } |
| 2214 | } else { |
| 2215 | // Wait for the request to complete |
| 2216 | while (request.result == null) { |
| 2217 | try { |
| 2218 | request.wait(); |
| 2219 | } catch (InterruptedException e) { |
| 2220 | // Do nothing, go back and wait until the request is complete |
| 2221 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2225 | if (request.result == null) { |
| 2226 | Log.wtf(LOG_TAG, |
| 2227 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | return request.result; |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2234 | * Posts the specified command to be executed on the main thread, and |
| 2235 | * returns immediately. |
| 2236 | * @see #sendRequest |
| 2237 | */ |
| 2238 | private void sendRequestAsync(int command) { |
| 2239 | mMainThreadHandler.sendEmptyMessage(command); |
| 2240 | } |
| 2241 | |
| 2242 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2243 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2244 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2245 | */ |
| 2246 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2247 | sendRequestAsync(command, argument, null, null); |
| 2248 | } |
| 2249 | |
| 2250 | /** |
| 2251 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2252 | * @see {@link #sendRequest(int,Object)} |
| 2253 | */ |
| 2254 | private void sendRequestAsync( |
| 2255 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2256 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2257 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2258 | msg.sendToTarget(); |
| 2259 | } |
| 2260 | |
| 2261 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2263 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2264 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2265 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | synchronized (PhoneInterfaceManager.class) { |
| 2267 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2268 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2269 | } else { |
| 2270 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2271 | } |
| 2272 | return sInstance; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2277 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2279 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2280 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2281 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2283 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2285 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2286 | mTelephonySharedPreferences = |
| 2287 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2288 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2289 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2290 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2291 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2292 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | publish(); |
| 2294 | } |
| 2295 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2296 | private Phone getDefaultPhone() { |
| 2297 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2298 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2299 | } |
| 2300 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | private void publish() { |
| 2302 | if (DBG) log("publish: " + this); |
| 2303 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2304 | TelephonyFrameworkInitializer |
| 2305 | .getTelephonyServiceManager() |
| 2306 | .getTelephonyServiceRegisterer() |
| 2307 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2310 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2311 | if (request.phone != null) { |
| 2312 | return request.phone; |
| 2313 | } else { |
| 2314 | return getPhoneFromSubId(request.subId); |
| 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | private Phone getPhoneFromSubId(int subId) { |
| 2319 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2320 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2323 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2324 | Phone phone = getPhoneFromRequest(request); |
| 2325 | return phone == null ? null : |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2326 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2327 | } |
| 2328 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2329 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2330 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2331 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2334 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2335 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2336 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2337 | } |
| 2338 | |
| 2339 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2340 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2341 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2344 | private boolean isImsAvailableOnDevice() { |
| 2345 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2346 | if (pm == null) { |
| 2347 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2348 | // so do not throw error and allow. |
| 2349 | return true; |
| 2350 | } |
| 2351 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2352 | } |
| 2353 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2355 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2358 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | if (DBG) log("dial: " + number); |
| 2360 | // No permission check needed here: This is just a wrapper around the |
| 2361 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2362 | // the UI before it does anything. |
| 2363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | final long identity = Binder.clearCallingIdentity(); |
| 2365 | try { |
| 2366 | String url = createTelUrl(number); |
| 2367 | if (url == null) { |
| 2368 | return; |
| 2369 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2370 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2371 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2372 | PhoneConstants.State state = mCM.getState(subId); |
| 2373 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2374 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2375 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2376 | mApp.startActivity(intent); |
| 2377 | } |
| 2378 | } finally { |
| 2379 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2384 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2387 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | if (DBG) log("call: " + number); |
| 2389 | |
| 2390 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2391 | // need to do a permission check since we're calling startActivity() |
| 2392 | // from the context of the phone app. |
| 2393 | enforceCallPermission(); |
| 2394 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2395 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | != AppOpsManager.MODE_ALLOWED) { |
| 2397 | return; |
| 2398 | } |
| 2399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2400 | final long identity = Binder.clearCallingIdentity(); |
| 2401 | try { |
| 2402 | String url = createTelUrl(number); |
| 2403 | if (url == null) { |
| 2404 | return; |
| 2405 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2407 | boolean isValid = false; |
| 2408 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2409 | if (slist != null) { |
| 2410 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2411 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2412 | isValid = true; |
| 2413 | break; |
| 2414 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2415 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2416 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | if (!isValid) { |
| 2418 | return; |
| 2419 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2420 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2421 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2422 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2423 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2424 | mApp.startActivity(intent); |
| 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
| 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2430 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2431 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2432 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2433 | } |
| 2434 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2435 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2436 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2437 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2438 | } |
| 2439 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2440 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2442 | |
| 2443 | final long identity = Binder.clearCallingIdentity(); |
| 2444 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2445 | Phone phone = getPhone(subId); |
| 2446 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2447 | checkSimPin.start(); |
| 2448 | return checkSimPin.unlockSim(null, pin); |
| 2449 | } finally { |
| 2450 | Binder.restoreCallingIdentity(identity); |
| 2451 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | } |
| 2453 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2454 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2456 | |
| 2457 | final long identity = Binder.clearCallingIdentity(); |
| 2458 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2459 | Phone phone = getPhone(subId); |
| 2460 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2461 | checkSimPuk.start(); |
| 2462 | return checkSimPuk.unlockSim(puk, pin); |
| 2463 | } finally { |
| 2464 | Binder.restoreCallingIdentity(identity); |
| 2465 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2469 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | * a synchronous one. |
| 2471 | */ |
| 2472 | private static class UnlockSim extends Thread { |
| 2473 | |
| 2474 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2475 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | |
| 2477 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2478 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2479 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | |
| 2481 | // For replies from SimCard interface |
| 2482 | private Handler mHandler; |
| 2483 | |
| 2484 | // For async handler to identify request type |
| 2485 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2486 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2487 | UnlockSim(int phoneId, IccCard simCard) { |
| 2488 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | mSimCard = simCard; |
| 2490 | } |
| 2491 | |
| 2492 | @Override |
| 2493 | public void run() { |
| 2494 | Looper.prepare(); |
| 2495 | synchronized (UnlockSim.this) { |
| 2496 | mHandler = new Handler() { |
| 2497 | @Override |
| 2498 | public void handleMessage(Message msg) { |
| 2499 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2500 | switch (msg.what) { |
| 2501 | case SUPPLY_PIN_COMPLETE: |
| 2502 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2503 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2504 | mRetryCount = msg.arg1; |
| 2505 | if (ar.exception != null) { |
| 2506 | if (ar.exception instanceof CommandException && |
| 2507 | ((CommandException)(ar.exception)).getCommandError() |
| 2508 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2509 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2510 | } //When UiccCardApp dispose,handle message and return exception |
| 2511 | else if (ar.exception instanceof CommandException && |
| 2512 | ((CommandException) (ar.exception)).getCommandError() |
| 2513 | == CommandException.Error.ABORTED) { |
| 2514 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2515 | } else { |
| 2516 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2517 | } |
| 2518 | } else { |
| 2519 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | mDone = true; |
| 2522 | UnlockSim.this.notifyAll(); |
| 2523 | } |
| 2524 | break; |
| 2525 | } |
| 2526 | } |
| 2527 | }; |
| 2528 | UnlockSim.this.notifyAll(); |
| 2529 | } |
| 2530 | Looper.loop(); |
| 2531 | } |
| 2532 | |
| 2533 | /* |
| 2534 | * Use PIN or PUK to unlock SIM card |
| 2535 | * |
| 2536 | * If PUK is null, unlock SIM card with PIN |
| 2537 | * |
| 2538 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2539 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2540 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | |
| 2542 | while (mHandler == null) { |
| 2543 | try { |
| 2544 | wait(); |
| 2545 | } catch (InterruptedException e) { |
| 2546 | Thread.currentThread().interrupt(); |
| 2547 | } |
| 2548 | } |
| 2549 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2550 | |
| 2551 | if (puk == null) { |
| 2552 | mSimCard.supplyPin(pin, callback); |
| 2553 | } else { |
| 2554 | mSimCard.supplyPuk(puk, pin, callback); |
| 2555 | } |
| 2556 | |
| 2557 | while (!mDone) { |
| 2558 | try { |
| 2559 | Log.d(LOG_TAG, "wait for done"); |
| 2560 | wait(); |
| 2561 | } catch (InterruptedException e) { |
| 2562 | // Restore the interrupted status |
| 2563 | Thread.currentThread().interrupt(); |
| 2564 | } |
| 2565 | } |
| 2566 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2567 | int[] resultArray = new int[2]; |
| 2568 | resultArray[0] = mResult; |
| 2569 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2570 | |
| 2571 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2572 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2575 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2579 | /** |
| 2580 | * This method has been removed due to privacy and stability concerns. |
| 2581 | */ |
| 2582 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2584 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2585 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2588 | @Override |
| 2589 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2590 | mApp.getSystemService(AppOpsManager.class) |
| 2591 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2592 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2593 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2594 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2595 | // Callers targeting S have no business invoking this method. |
| 2596 | return; |
| 2597 | } |
| 2598 | |
| 2599 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2600 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2601 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2602 | .setCallingPackage(callingPackage) |
| 2603 | .setCallingFeatureId(null) |
| 2604 | .setCallingPid(Binder.getCallingPid()) |
| 2605 | .setCallingUid(Binder.getCallingUid()) |
| 2606 | .setMethod("updateServiceLocation") |
| 2607 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2608 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2609 | .build()); |
| 2610 | // Apps that lack location permission have no business calling this method; |
| 2611 | // however, because no permission was declared in the public API, denials must |
| 2612 | // all be "soft". |
| 2613 | switch (locationResult) { |
| 2614 | case DENIED_HARD: /* fall through */ |
| 2615 | case DENIED_SOFT: |
| 2616 | return; |
| 2617 | } |
| 2618 | |
| 2619 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | final long identity = Binder.clearCallingIdentity(); |
| 2621 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2622 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2624 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | } |
| 2626 | } finally { |
| 2627 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2631 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2632 | @Override |
| 2633 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2634 | return isRadioOnWithFeature(callingPackage, null); |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | @Override |
| 2639 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2640 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2641 | callingFeatureId); |
| 2642 | } |
| 2643 | |
| 2644 | @Deprecated |
| 2645 | @Override |
| 2646 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2647 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2650 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2651 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2652 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2653 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2654 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2655 | return false; |
| 2656 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | |
| 2658 | final long identity = Binder.clearCallingIdentity(); |
| 2659 | try { |
| 2660 | return isRadioOnForSubscriber(subId); |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | final long identity = Binder.clearCallingIdentity(); |
| 2668 | try { |
| 2669 | final Phone phone = getPhone(subId); |
| 2670 | if (phone != null) { |
| 2671 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2672 | } else { |
| 2673 | return false; |
| 2674 | } |
| 2675 | } finally { |
| 2676 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2681 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2683 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2684 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | |
| 2687 | final long identity = Binder.clearCallingIdentity(); |
| 2688 | try { |
| 2689 | final Phone phone = getPhone(subId); |
| 2690 | if (phone != null) { |
| 2691 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2692 | } |
| 2693 | } finally { |
| 2694 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2695 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2699 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2702 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2703 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2704 | |
| 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
| 2707 | final Phone phone = getPhone(subId); |
| 2708 | if (phone == null) { |
| 2709 | return false; |
| 2710 | } |
| 2711 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2712 | toggleRadioOnOffForSubscriber(subId); |
| 2713 | } |
| 2714 | return true; |
| 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2719 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2720 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2721 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2722 | /* |
| 2723 | * If any of the Radios are available, it will need to be |
| 2724 | * shutdown. So return true if any Radio is available. |
| 2725 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | final long identity = Binder.clearCallingIdentity(); |
| 2727 | try { |
| 2728 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2729 | Phone phone = PhoneFactory.getPhone(i); |
| 2730 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2731 | } |
| 2732 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2733 | return false; |
| 2734 | } finally { |
| 2735 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2736 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2740 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2741 | enforceModifyPermission(); |
| 2742 | |
| 2743 | final long identity = Binder.clearCallingIdentity(); |
| 2744 | try { |
| 2745 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2746 | logv("Shutting down Phone " + i); |
| 2747 | shutdownRadioUsingPhoneId(i); |
| 2748 | } |
| 2749 | } finally { |
| 2750 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2755 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2756 | if (phone != null && phone.isRadioAvailable()) { |
| 2757 | phone.shutdownRadio(); |
| 2758 | } |
| 2759 | } |
| 2760 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2761 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2762 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | |
| 2764 | final long identity = Binder.clearCallingIdentity(); |
| 2765 | try { |
| 2766 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2767 | if (defaultPhone != null) { |
| 2768 | defaultPhone.setRadioPower(turnOn); |
| 2769 | return true; |
| 2770 | } else { |
| 2771 | loge("There's no default phone."); |
| 2772 | return false; |
| 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2776 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2779 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2781 | |
| 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | final Phone phone = getPhone(subId); |
| 2785 | if (phone != null) { |
| 2786 | phone.setRadioPower(turnOn); |
| 2787 | return true; |
| 2788 | } else { |
| 2789 | return false; |
| 2790 | } |
| 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2793 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2796 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2797 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | public boolean enableDataConnectivity() { |
| 2799 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2800 | |
| 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2804 | final Phone phone = getPhone(subId); |
| 2805 | if (phone != null) { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2806 | if (phone.isUsingNewDataStack()) { |
| 2807 | phone.getDataSettingsManager().setDataEnabled( |
| 2808 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2809 | } else { |
| 2810 | phone.getDataEnabledSettings().setDataEnabled( |
| 2811 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2812 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2813 | return true; |
| 2814 | } else { |
| 2815 | return false; |
| 2816 | } |
| 2817 | } finally { |
| 2818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2822 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2823 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | public boolean disableDataConnectivity() { |
| 2825 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | |
| 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
| 2829 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2830 | final Phone phone = getPhone(subId); |
| 2831 | if (phone != null) { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2832 | if (phone.isUsingNewDataStack()) { |
| 2833 | phone.getDataSettingsManager().setDataEnabled( |
| 2834 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2835 | } else { |
| 2836 | phone.getDataEnabledSettings().setDataEnabled( |
| 2837 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2838 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2839 | return true; |
| 2840 | } else { |
| 2841 | return false; |
| 2842 | } |
| 2843 | } finally { |
| 2844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2848 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2849 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2850 | final long identity = Binder.clearCallingIdentity(); |
| 2851 | try { |
| 2852 | final Phone phone = getPhone(subId); |
| 2853 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2854 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2855 | } else { |
| 2856 | return false; |
| 2857 | } |
| 2858 | } finally { |
| 2859 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2860 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2864 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2867 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2868 | enforceCallPermission(); |
| 2869 | |
| 2870 | final long identity = Binder.clearCallingIdentity(); |
| 2871 | try { |
| 2872 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2873 | return; |
| 2874 | } |
| 2875 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2876 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2877 | } finally { |
| 2878 | Binder.restoreCallingIdentity(identity); |
| 2879 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2880 | }; |
| 2881 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2882 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2884 | |
| 2885 | final long identity = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2888 | return false; |
| 2889 | } |
| 2890 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2891 | } finally { |
| 2892 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2893 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2896 | /** |
| 2897 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2898 | * tag on getCallState Binder call. |
| 2899 | */ |
| 2900 | @Deprecated |
| 2901 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2902 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2903 | if (CompatChanges.isChangeEnabled( |
| 2904 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2905 | Binder.getCallingUid())) { |
| 2906 | // Do not allow this API to be called on API version 31+, it should only be |
| 2907 | // called on old apps using this Binder call directly. |
| 2908 | throw new SecurityException("This method can only be used for applications " |
| 2909 | + "targeting API version 30 or less."); |
| 2910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | final long identity = Binder.clearCallingIdentity(); |
| 2912 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2913 | Phone phone = getPhone(getDefaultSubscription()); |
| 2914 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2915 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(identity); |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | @Override |
| 2922 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2923 | if (CompatChanges.isChangeEnabled( |
| 2924 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2925 | Binder.getCallingUid())) { |
| 2926 | // Check READ_PHONE_STATE for API version 31+ |
| 2927 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2928 | featureId, "getCallStateForSubscription")) { |
| 2929 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2930 | + "targeting API level 31+."); |
| 2931 | } |
| 2932 | } |
| 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
| 2935 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2937 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
| 2940 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2943 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2944 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2945 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2946 | } |
| 2947 | |
| 2948 | @Override |
| 2949 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | final long identity = Binder.clearCallingIdentity(); |
| 2951 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2952 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2953 | if (phone != null) { |
Jack Yu | 4accbd9 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 2954 | if (phone.isUsingNewDataStack()) { |
| 2955 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 2956 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2958 | } else { |
| 2959 | return PhoneConstantConversions.convertDataState( |
| 2960 | PhoneConstants.DataState.DISCONNECTED); |
| 2961 | } |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2964 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2967 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2968 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2969 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
| 2973 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2976 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | if (phone != null) { |
| 2978 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2979 | } else { |
| 2980 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2981 | } |
| 2982 | } finally { |
| 2983 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2984 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2988 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2989 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2990 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2991 | |
| 2992 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2993 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2994 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2995 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2996 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2997 | .setCallingPid(Binder.getCallingPid()) |
| 2998 | .setCallingUid(Binder.getCallingUid()) |
| 2999 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3000 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3001 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3002 | .build()); |
| 3003 | switch (locationResult) { |
| 3004 | case DENIED_HARD: |
| 3005 | throw new SecurityException("Not allowed to access cell location"); |
| 3006 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3007 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3008 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3011 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | final long identity = Binder.clearCallingIdentity(); |
| 3013 | try { |
| 3014 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3015 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3016 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3022 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3023 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3024 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3025 | // registered cell info, so return a NULL country instead. |
| 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3028 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3029 | // Get default phone in this case. |
| 3030 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3031 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3032 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3034 | if (phone == null) return ""; |
| 3035 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3036 | if (sst == null) return ""; |
| 3037 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3038 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3039 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
| 3042 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3045 | /** |
| 3046 | * This method was removed due to potential issues caused by performing partial |
| 3047 | * updates of service state, and lack of a credible use case. |
| 3048 | * |
| 3049 | * This has the ability to break the telephony implementation by disabling notification of |
| 3050 | * changes in device connectivity. DO NOT USE THIS! |
| 3051 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3052 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3053 | public void enableLocationUpdates() { |
| 3054 | mApp.enforceCallingOrSelfPermission( |
| 3055 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3058 | /** |
| 3059 | * This method was removed due to potential issues caused by performing partial |
| 3060 | * updates of service state, and lack of a credible use case. |
| 3061 | * |
| 3062 | * This has the ability to break the telephony implementation by disabling notification of |
| 3063 | * changes in device connectivity. DO NOT USE THIS! |
| 3064 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3065 | @Override |
| 3066 | public void disableLocationUpdates() { |
| 3067 | mApp.enforceCallingOrSelfPermission( |
| 3068 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | @Override |
| 3072 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3073 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3074 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3075 | try { |
| 3076 | mApp.getSystemService(AppOpsManager.class) |
| 3077 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3078 | } catch (SecurityException e) { |
| 3079 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3080 | throw e; |
| 3081 | } |
| 3082 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3083 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3084 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3085 | throw new SecurityException( |
| 3086 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3087 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3088 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3089 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3090 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3091 | return null; |
| 3092 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3093 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3094 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3095 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3096 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3097 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3099 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3100 | for (CellInfo ci : info) { |
| 3101 | if (ci instanceof CellInfoGsm) { |
| 3102 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3103 | } else if (ci instanceof CellInfoWcdma) { |
| 3104 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3106 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3107 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3110 | private List<CellInfo> getCachedCellInfo() { |
| 3111 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3112 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3113 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3114 | if (info != null) cellInfos.addAll(info); |
| 3115 | } |
| 3116 | return cellInfos; |
| 3117 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3118 | |
| 3119 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3120 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3121 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3122 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3123 | |
| 3124 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3125 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3126 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3127 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3128 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3129 | .setCallingPid(Binder.getCallingPid()) |
| 3130 | .setCallingUid(Binder.getCallingUid()) |
| 3131 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3132 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3133 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3134 | .build()); |
| 3135 | switch (locationResult) { |
| 3136 | case DENIED_HARD: |
| 3137 | throw new SecurityException("Not allowed to access cell info"); |
| 3138 | case DENIED_SOFT: |
| 3139 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3142 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3143 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3144 | return getCachedCellInfo(); |
| 3145 | } |
| 3146 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3147 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3148 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
| 3151 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3152 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3153 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3154 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3155 | if (info != null) cellInfos.addAll(info); |
| 3156 | } |
| 3157 | return cellInfos; |
| 3158 | } finally { |
| 3159 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3160 | } |
| 3161 | } |
| 3162 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3163 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3164 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3165 | String callingFeatureId) { |
| 3166 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3167 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3171 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3172 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3173 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3174 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3175 | } |
| 3176 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3177 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3178 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3179 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3180 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3181 | |
| 3182 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3183 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3184 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3185 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3186 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3187 | .setCallingPid(Binder.getCallingPid()) |
| 3188 | .setCallingUid(Binder.getCallingUid()) |
| 3189 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3190 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3191 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3192 | .build()); |
| 3193 | switch (locationResult) { |
| 3194 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3195 | if (TelephonyPermissions |
| 3196 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3197 | // Safetynet logging for b/154934934 |
| 3198 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3199 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3200 | throw new SecurityException("Not allowed to access cell info"); |
| 3201 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3202 | if (TelephonyPermissions |
| 3203 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3204 | // Safetynet logging for b/154934934 |
| 3205 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3206 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3207 | try { |
| 3208 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3209 | } catch (RemoteException re) { |
| 3210 | // Drop without consequences |
| 3211 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3212 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3215 | |
| 3216 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3217 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3218 | |
| 3219 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3220 | } |
| 3221 | |
| 3222 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3223 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3224 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3225 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | |
| 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3229 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | } finally { |
| 3231 | Binder.restoreCallingIdentity(identity); |
| 3232 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3235 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3236 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3237 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3238 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3239 | return null; |
| 3240 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3241 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3242 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3243 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3244 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3245 | return null; |
| 3246 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | |
| 3248 | final long identity = Binder.clearCallingIdentity(); |
| 3249 | try { |
| 3250 | return phone.getImei(); |
| 3251 | } finally { |
| 3252 | Binder.restoreCallingIdentity(identity); |
| 3253 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3257 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3258 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3259 | String tac = null; |
| 3260 | if (phone != null) { |
| 3261 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3262 | try { |
| 3263 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3264 | } catch (IndexOutOfBoundsException e) { |
| 3265 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3266 | return null; |
| 3267 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3268 | } |
| 3269 | return tac; |
| 3270 | } |
| 3271 | |
| 3272 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3273 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3274 | try { |
| 3275 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3276 | } catch (SecurityException se) { |
| 3277 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3278 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3279 | + Binder.getCallingUid()); |
| 3280 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3281 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3282 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3283 | return null; |
| 3284 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3285 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3286 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3287 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3288 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3289 | return null; |
| 3290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3291 | |
| 3292 | final long identity = Binder.clearCallingIdentity(); |
| 3293 | try { |
| 3294 | return phone.getMeid(); |
| 3295 | } finally { |
| 3296 | Binder.restoreCallingIdentity(identity); |
| 3297 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3301 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3302 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3303 | String manufacturerCode = null; |
| 3304 | if (phone != null) { |
| 3305 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3306 | try { |
| 3307 | manufacturerCode = |
| 3308 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3309 | } catch (IndexOutOfBoundsException e) { |
| 3310 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3311 | return null; |
| 3312 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3313 | } |
| 3314 | return manufacturerCode; |
| 3315 | } |
| 3316 | |
| 3317 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3318 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3319 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3320 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3321 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3322 | return null; |
| 3323 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3324 | int subId = phone.getSubId(); |
| 3325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3326 | mApp, subId, callingPackage, callingFeatureId, |
| 3327 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3328 | return null; |
| 3329 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | |
| 3331 | final long identity = Binder.clearCallingIdentity(); |
| 3332 | try { |
| 3333 | return phone.getDeviceSvn(); |
| 3334 | } finally { |
| 3335 | Binder.restoreCallingIdentity(identity); |
| 3336 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3339 | @Override |
| 3340 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3341 | final long identity = Binder.clearCallingIdentity(); |
| 3342 | try { |
| 3343 | final Phone phone = getPhone(subId); |
| 3344 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3345 | } finally { |
| 3346 | Binder.restoreCallingIdentity(identity); |
| 3347 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | @Override |
| 3351 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | final long identity = Binder.clearCallingIdentity(); |
| 3353 | try { |
| 3354 | final Phone phone = getPhone(subId); |
| 3355 | return phone == null ? null : phone.getCarrierName(); |
| 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
| 3358 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3359 | } |
| 3360 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3361 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3362 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3363 | final long identity = Binder.clearCallingIdentity(); |
| 3364 | try { |
| 3365 | final Phone phone = getPhone(subId); |
| 3366 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3367 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3368 | } finally { |
| 3369 | Binder.restoreCallingIdentity(identity); |
| 3370 | } |
| 3371 | } |
| 3372 | |
| 3373 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3374 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3375 | final long identity = Binder.clearCallingIdentity(); |
| 3376 | try { |
| 3377 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3378 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3379 | } finally { |
| 3380 | Binder.restoreCallingIdentity(identity); |
| 3381 | } |
| 3382 | } |
| 3383 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3384 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3385 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3386 | if (!isSubscriptionMccMnc) { |
| 3387 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3388 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3389 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3390 | if (phone == null) { |
| 3391 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3392 | } |
| 3393 | final long identity = Binder.clearCallingIdentity(); |
| 3394 | try { |
| 3395 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3396 | } finally { |
| 3397 | Binder.restoreCallingIdentity(identity); |
| 3398 | } |
| 3399 | } |
| 3400 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3401 | // |
| 3402 | // Internal helper methods. |
| 3403 | // |
| 3404 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3405 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3406 | * Make sure the caller is the calling package itself |
| 3407 | * |
| 3408 | * @throws SecurityException if the caller is not the calling package |
| 3409 | */ |
| 3410 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3411 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3412 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3413 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3414 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3415 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3416 | } catch (PackageManager.NameNotFoundException e) { |
| 3417 | // packageUid is -1 |
| 3418 | } |
| 3419 | if (packageUid != callingUid) { |
| 3420 | throw new SecurityException(message + ": Package " + callingPackage |
| 3421 | + " does not belong to " + callingUid); |
| 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3426 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3427 | * |
| 3428 | * @throws SecurityException if the caller does not have the required permission |
| 3429 | */ |
| 3430 | private void enforceModifyPermission() { |
| 3431 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3432 | } |
| 3433 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3434 | private void enforceActiveEmergencySessionPermission() { |
| 3435 | mApp.enforceCallingOrSelfPermission( |
| 3436 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3437 | } |
| 3438 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3439 | /** |
| 3440 | * Make sure the caller has the CALL_PHONE permission. |
| 3441 | * |
| 3442 | * @throws SecurityException if the caller does not have the required permission |
| 3443 | */ |
| 3444 | private void enforceCallPermission() { |
| 3445 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3446 | } |
| 3447 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3448 | private void enforceSettingsPermission() { |
| 3449 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3452 | private void enforceRebootPermission() { |
| 3453 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3454 | } |
| 3455 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3456 | private String createTelUrl(String number) { |
| 3457 | if (TextUtils.isEmpty(number)) { |
| 3458 | return null; |
| 3459 | } |
| 3460 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3461 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3464 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3465 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3466 | } |
| 3467 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3468 | private static void logv(String msg) { |
| 3469 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3470 | } |
| 3471 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3472 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3473 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3474 | } |
| 3475 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3476 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3477 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3478 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3479 | } |
| 3480 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3481 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3482 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3483 | final long identity = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3486 | if (phone == null) { |
| 3487 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3488 | } else { |
| 3489 | return phone.getPhoneType(); |
| 3490 | } |
| 3491 | } finally { |
| 3492 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3493 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | /** |
| 3497 | * Returns the CDMA ERI icon index to display |
| 3498 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3499 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3500 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3501 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3502 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3505 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3506 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3507 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3508 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3509 | mApp, subId, callingPackage, callingFeatureId, |
| 3510 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3511 | return -1; |
| 3512 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3513 | |
| 3514 | final long identity = Binder.clearCallingIdentity(); |
| 3515 | try { |
| 3516 | final Phone phone = getPhone(subId); |
| 3517 | if (phone != null) { |
| 3518 | return phone.getCdmaEriIconIndex(); |
| 3519 | } else { |
| 3520 | return -1; |
| 3521 | } |
| 3522 | } finally { |
| 3523 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | /** |
| 3528 | * Returns the CDMA ERI icon mode, |
| 3529 | * 0 - ON |
| 3530 | * 1 - FLASHING |
| 3531 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3532 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3533 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3534 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3535 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3539 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3540 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3542 | mApp, subId, callingPackage, callingFeatureId, |
| 3543 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3544 | return -1; |
| 3545 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | final Phone phone = getPhone(subId); |
| 3550 | if (phone != null) { |
| 3551 | return phone.getCdmaEriIconMode(); |
| 3552 | } else { |
| 3553 | return -1; |
| 3554 | } |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3557 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | /** |
| 3561 | * Returns the CDMA ERI text, |
| 3562 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3563 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3564 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3565 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3566 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3569 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3570 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3571 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3573 | mApp, subId, callingPackage, callingFeatureId, |
| 3574 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3575 | return null; |
| 3576 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3577 | |
| 3578 | final long identity = Binder.clearCallingIdentity(); |
| 3579 | try { |
| 3580 | final Phone phone = getPhone(subId); |
| 3581 | if (phone != null) { |
| 3582 | return phone.getCdmaEriText(); |
| 3583 | } else { |
| 3584 | return null; |
| 3585 | } |
| 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3588 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3592 | * Returns the CDMA MDN. |
| 3593 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3594 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3595 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3597 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3598 | |
| 3599 | final long identity = Binder.clearCallingIdentity(); |
| 3600 | try { |
| 3601 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3602 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3603 | return phone.getLine1Number(); |
| 3604 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3605 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3606 | return null; |
| 3607 | } |
| 3608 | } finally { |
| 3609 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * Returns the CDMA MIN. |
| 3615 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3616 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3617 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3619 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | |
| 3621 | final long identity = Binder.clearCallingIdentity(); |
| 3622 | try { |
| 3623 | final Phone phone = getPhone(subId); |
| 3624 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3625 | return phone.getCdmaMin(); |
| 3626 | } else { |
| 3627 | return null; |
| 3628 | } |
| 3629 | } finally { |
| 3630 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3634 | @Override |
| 3635 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3636 | INumberVerificationCallback callback, String callingPackage) { |
| 3637 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3638 | != PERMISSION_GRANTED) { |
| 3639 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3640 | } |
| 3641 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3642 | |
| 3643 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3644 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3645 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3646 | + "calling package: " + callingPackage |
| 3647 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | if (range == null) { |
| 3651 | throw new NullPointerException("Range must be non-null"); |
| 3652 | } |
| 3653 | |
| 3654 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3655 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3656 | |
| 3657 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3658 | } |
| 3659 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3660 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3661 | * Returns true if CDMA provisioning needs to run. |
| 3662 | */ |
| 3663 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3666 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
| 3669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3673 | * Sets the voice mail number of a given subId. |
| 3674 | */ |
| 3675 | @Override |
| 3676 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3677 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3678 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3679 | |
| 3680 | final long identity = Binder.clearCallingIdentity(); |
| 3681 | try { |
| 3682 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3683 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3684 | return success; |
| 3685 | } finally { |
| 3686 | Binder.restoreCallingIdentity(identity); |
| 3687 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3688 | } |
| 3689 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3690 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3691 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3692 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3693 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3694 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3695 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3696 | throw new SecurityException("caller must be system dialer"); |
| 3697 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3698 | |
| 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
| 3701 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3702 | if (phoneAccountHandle == null) { |
| 3703 | return null; |
| 3704 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3705 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3708 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3712 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3713 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3714 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3715 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3716 | mApp, subId, callingPackage, callingFeatureId, |
| 3717 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3718 | return null; |
| 3719 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3720 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3721 | final long identity = Binder.clearCallingIdentity(); |
| 3722 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3723 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3724 | } finally { |
| 3725 | Binder.restoreCallingIdentity(identity); |
| 3726 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3730 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3731 | VisualVoicemailSmsFilterSettings settings) { |
| 3732 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3733 | |
| 3734 | final long identity = Binder.clearCallingIdentity(); |
| 3735 | try { |
| 3736 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3737 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3738 | } finally { |
| 3739 | Binder.restoreCallingIdentity(identity); |
| 3740 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3744 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3745 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | |
| 3747 | final long identity = Binder.clearCallingIdentity(); |
| 3748 | try { |
| 3749 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3750 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | } finally { |
| 3752 | Binder.restoreCallingIdentity(identity); |
| 3753 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3757 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3758 | String callingPackage, int subId) { |
| 3759 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3760 | |
| 3761 | final long identity = Binder.clearCallingIdentity(); |
| 3762 | try { |
| 3763 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3764 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(identity); |
| 3767 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3771 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3772 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3773 | |
| 3774 | final long identity = Binder.clearCallingIdentity(); |
| 3775 | try { |
| 3776 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3777 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3778 | } finally { |
| 3779 | Binder.restoreCallingIdentity(identity); |
| 3780 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3784 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3785 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3786 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3787 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3788 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3789 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3790 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3791 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3792 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3793 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3794 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3795 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3796 | * Sets the voice activation state of a given subId. |
| 3797 | */ |
| 3798 | @Override |
| 3799 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3800 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3801 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | |
| 3803 | final long identity = Binder.clearCallingIdentity(); |
| 3804 | try { |
| 3805 | final Phone phone = getPhone(subId); |
| 3806 | if (phone != null) { |
| 3807 | phone.setVoiceActivationState(activationState); |
| 3808 | } else { |
| 3809 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3810 | } |
| 3811 | } finally { |
| 3812 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | /** |
| 3817 | * Sets the data activation state of a given subId. |
| 3818 | */ |
| 3819 | @Override |
| 3820 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3822 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3823 | |
| 3824 | final long identity = Binder.clearCallingIdentity(); |
| 3825 | try { |
| 3826 | final Phone phone = getPhone(subId); |
| 3827 | if (phone != null) { |
| 3828 | phone.setDataActivationState(activationState); |
| 3829 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3830 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | } |
| 3832 | } finally { |
| 3833 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | /** |
| 3838 | * Returns the voice activation state of a given subId. |
| 3839 | */ |
| 3840 | @Override |
| 3841 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3842 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3843 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3844 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | if (phone != null) { |
| 3848 | return phone.getVoiceActivationState(); |
| 3849 | } else { |
| 3850 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3851 | } |
| 3852 | } finally { |
| 3853 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | /** |
| 3858 | * Returns the data activation state of a given subId. |
| 3859 | */ |
| 3860 | @Override |
| 3861 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3862 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3864 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3865 | final long identity = Binder.clearCallingIdentity(); |
| 3866 | try { |
| 3867 | if (phone != null) { |
| 3868 | return phone.getDataActivationState(); |
| 3869 | } else { |
| 3870 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3871 | } |
| 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3878 | * Returns the unread count of voicemails for a subId |
| 3879 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3880 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3881 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3882 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3884 | mApp, subId, callingPackage, callingFeatureId, |
| 3885 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3886 | return 0; |
| 3887 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3888 | final long identity = Binder.clearCallingIdentity(); |
| 3889 | try { |
| 3890 | final Phone phone = getPhone(subId); |
| 3891 | if (phone != null) { |
| 3892 | return phone.getVoiceMessageCount(); |
| 3893 | } else { |
| 3894 | return 0; |
| 3895 | } |
| 3896 | } finally { |
| 3897 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3898 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3902 | * returns true, if the device is in a state where both voice and data |
| 3903 | * are supported simultaneously. This can change based on location or network condition. |
| 3904 | */ |
| 3905 | @Override |
| 3906 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3907 | final long identity = Binder.clearCallingIdentity(); |
| 3908 | try { |
| 3909 | final Phone phone = getPhone(subId); |
| 3910 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3911 | } finally { |
| 3912 | Binder.restoreCallingIdentity(identity); |
| 3913 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3917 | * Send the dialer code if called from the current default dialer or the caller has |
| 3918 | * carrier privilege. |
| 3919 | * @param inputCode The dialer code to send |
| 3920 | */ |
| 3921 | @Override |
| 3922 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3923 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3924 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3925 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3926 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3927 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3928 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3929 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3930 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3931 | |
| 3932 | final long identity = Binder.clearCallingIdentity(); |
| 3933 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3934 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(identity); |
| 3937 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3938 | } |
| 3939 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3940 | @Override |
| 3941 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3942 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3943 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3944 | mApp, subId, "getNetworkSelectionMode"); |
| 3945 | final long identity = Binder.clearCallingIdentity(); |
| 3946 | try { |
| 3947 | if (!isActiveSubscription(subId)) { |
| 3948 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3949 | } |
| 3950 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3951 | } finally { |
| 3952 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3953 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3954 | } |
| 3955 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3956 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3957 | public boolean isInEmergencySmsMode() { |
| 3958 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3959 | final long identity = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3962 | if (phone.isInEmergencySmsMode()) { |
| 3963 | return true; |
| 3964 | } |
| 3965 | } |
| 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
| 3968 | } |
| 3969 | return false; |
| 3970 | } |
| 3971 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3972 | /** |
| 3973 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3974 | * @param subId The subscription to use to check the configuration. |
| 3975 | * @param c The callback that will be used to send the result. |
| 3976 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3977 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3978 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3979 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3980 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3981 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3982 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3983 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3984 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3985 | "IMS not available on device."); |
| 3986 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3987 | final long token = Binder.clearCallingIdentity(); |
| 3988 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 3989 | int slotId = getSlotIndexOrException(subId); |
| 3990 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 3991 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3992 | } catch (ImsException e) { |
| 3993 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | } finally { |
| 3995 | Binder.restoreCallingIdentity(token); |
| 3996 | } |
| 3997 | } |
| 3998 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3999 | /** |
| 4000 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4001 | * @param subId The subscription to use to check the configuration. |
| 4002 | * @param c The callback that will be used to send the result. |
| 4003 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4004 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4005 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4006 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4007 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4008 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4009 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4010 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4011 | final long token = Binder.clearCallingIdentity(); |
| 4012 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4013 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4014 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4015 | } catch (ImsException e) { |
| 4016 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4017 | + "is inactive, ignoring unregister."); |
| 4018 | // If the subscription is no longer active, just return, since the callback |
| 4019 | // will already have been removed internally. |
| 4020 | } finally { |
| 4021 | Binder.restoreCallingIdentity(token); |
| 4022 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4025 | /** |
| 4026 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4027 | */ |
| 4028 | @Override |
| 4029 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4030 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4031 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4032 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4033 | "IMS not available on device."); |
| 4034 | } |
| 4035 | final long token = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | Phone phone = getPhone(subId); |
| 4038 | if (phone == null) { |
| 4039 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4040 | + subId + "'"); |
| 4041 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4042 | } |
| 4043 | phone.getImsRegistrationState(regState -> { |
| 4044 | try { |
| 4045 | consumer.accept((regState == null) |
| 4046 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4047 | } catch (RemoteException e) { |
| 4048 | // Ignore if the remote process is no longer available to call back. |
| 4049 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4050 | } |
| 4051 | }); |
| 4052 | } finally { |
| 4053 | Binder.restoreCallingIdentity(token); |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | /** |
| 4058 | * Get the transport type for the IMS service registration state. |
| 4059 | */ |
| 4060 | @Override |
| 4061 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4062 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4063 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4064 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4065 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4066 | "IMS not available on device."); |
| 4067 | } |
| 4068 | final long token = Binder.clearCallingIdentity(); |
| 4069 | try { |
| 4070 | Phone phone = getPhone(subId); |
| 4071 | if (phone == null) { |
| 4072 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4073 | + subId + "'"); |
| 4074 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4075 | } |
| 4076 | phone.getImsRegistrationTech(regTech -> { |
| 4077 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4078 | int regTechConverted = (regTech == null) |
| 4079 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4080 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4081 | regTechConverted); |
| 4082 | try { |
| 4083 | consumer.accept(regTechConverted); |
| 4084 | } catch (RemoteException e) { |
| 4085 | // Ignore if the remote process is no longer available to call back. |
| 4086 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4087 | } |
| 4088 | }); |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(token); |
| 4091 | } |
| 4092 | } |
| 4093 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4094 | /** |
| 4095 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4096 | * @param subId The subscription to use to check the configuration. |
| 4097 | * @param c The callback that will be used to send the result. |
| 4098 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4099 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4100 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4101 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4102 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4103 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4104 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4105 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4106 | "IMS not available on device."); |
| 4107 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4108 | final long token = Binder.clearCallingIdentity(); |
| 4109 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4110 | int slotId = getSlotIndexOrException(subId); |
| 4111 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4112 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4113 | } catch (ImsException e) { |
| 4114 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | } finally { |
| 4116 | Binder.restoreCallingIdentity(token); |
| 4117 | } |
| 4118 | } |
| 4119 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4120 | /** |
| 4121 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4122 | * @param subId The subscription to use to check the configuration. |
| 4123 | * @param c The callback that will be used to send the result. |
| 4124 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4126 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4127 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4128 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4129 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4130 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4131 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4132 | |
| 4133 | final long token = Binder.clearCallingIdentity(); |
| 4134 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4135 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4136 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4137 | } catch (ImsException e) { |
| 4138 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4139 | + "is inactive, ignoring unregister."); |
| 4140 | // If the subscription is no longer active, just return, since the callback |
| 4141 | // will already have been removed internally. |
| 4142 | } finally { |
| 4143 | Binder.restoreCallingIdentity(token); |
| 4144 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4148 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4149 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4150 | final long token = Binder.clearCallingIdentity(); |
| 4151 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4152 | int slotId = getSlotIndexOrException(subId); |
| 4153 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4154 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4155 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4156 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4157 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4158 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4159 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4160 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(token); |
| 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4167 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4168 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4169 | final long token = Binder.clearCallingIdentity(); |
| 4170 | try { |
| 4171 | Phone phone = getPhone(subId); |
| 4172 | if (phone == null) return false; |
| 4173 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4174 | } catch (com.android.ims.ImsException e) { |
| 4175 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4176 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | } finally { |
| 4178 | Binder.restoreCallingIdentity(token); |
| 4179 | } |
| 4180 | } |
| 4181 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4182 | /** |
| 4183 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4184 | * subscription. |
| 4185 | * @param subId The subscription to use to check the configuration. |
| 4186 | * @param callback The callback that will be used to send the result. |
| 4187 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4188 | * @param transportType The transport type of the MmTelFeature capability. |
| 4189 | */ |
| 4190 | @Override |
| 4191 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4192 | int transportType) { |
| 4193 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4194 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4195 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4196 | "IMS not available on device."); |
| 4197 | } |
| 4198 | final long token = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | int slotId = getSlotIndex(subId); |
| 4201 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4202 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4203 | + subId + "'"); |
| 4204 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4205 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4206 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4207 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4208 | transportType, aBoolean -> { |
| 4209 | try { |
| 4210 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4211 | } catch (RemoteException e) { |
| 4212 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4213 | + "running. Ignore"); |
| 4214 | } |
| 4215 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4216 | } catch (ImsException e) { |
| 4217 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(token); |
| 4220 | } |
| 4221 | } |
| 4222 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4223 | /** |
| 4224 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4225 | * @param subId The subscription to use to check the configuration. |
| 4226 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4227 | @Override |
| 4228 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4229 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4230 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4231 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4232 | final long token = Binder.clearCallingIdentity(); |
| 4233 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4234 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4235 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4236 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4237 | } catch (ImsException e) { |
| 4238 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(token); |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4245 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4246 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4247 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4248 | final long identity = Binder.clearCallingIdentity(); |
| 4249 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4250 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4251 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4252 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4253 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4254 | } catch (ImsException e) { |
| 4255 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4256 | } finally { |
| 4257 | Binder.restoreCallingIdentity(identity); |
| 4258 | } |
| 4259 | } |
| 4260 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4261 | /** |
| 4262 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4263 | * @param subId The subscription to use to check the configuration. |
| 4264 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4265 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4266 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4267 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4268 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4271 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4272 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4273 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4274 | } catch (ImsException e) { |
| 4275 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4276 | } finally { |
| 4277 | Binder.restoreCallingIdentity(identity); |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4282 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4283 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4284 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4285 | final long identity = Binder.clearCallingIdentity(); |
| 4286 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4287 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4288 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4289 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4290 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4291 | } catch (ImsException e) { |
| 4292 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4293 | } finally { |
| 4294 | Binder.restoreCallingIdentity(identity); |
| 4295 | } |
| 4296 | } |
| 4297 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4298 | /** |
| 4299 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4300 | * @param subId The subscription to use to check the configuration. |
| 4301 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4302 | @Override |
| 4303 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4304 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4305 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4306 | final long identity = Binder.clearCallingIdentity(); |
| 4307 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4308 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4309 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4310 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4311 | } catch (ImsException e) { |
| 4312 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4313 | } finally { |
| 4314 | Binder.restoreCallingIdentity(identity); |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4319 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4321 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4322 | final long identity = Binder.clearCallingIdentity(); |
| 4323 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4324 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4325 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4326 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4327 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4328 | } catch (ImsException e) { |
| 4329 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4330 | } finally { |
| 4331 | Binder.restoreCallingIdentity(identity); |
| 4332 | } |
| 4333 | } |
| 4334 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4335 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4336 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4337 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4338 | * @param subId The subscription to use to check the configuration. |
| 4339 | */ |
| 4340 | @Override |
| 4341 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4342 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4343 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4344 | final long identity = Binder.clearCallingIdentity(); |
| 4345 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4346 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4347 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4348 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4349 | } catch (ImsException e) { |
| 4350 | throw new ServiceSpecificException(e.getCode()); |
| 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | /** |
| 4357 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4358 | * Requires MODIFY_PHONE_STATE permission. |
| 4359 | * @param subId The subscription to use to check the configuration. |
| 4360 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4361 | * false otherwise |
| 4362 | */ |
| 4363 | @Override |
| 4364 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4366 | "setCrossSimCallingEnabled"); |
| 4367 | final long identity = Binder.clearCallingIdentity(); |
| 4368 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4369 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4370 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4371 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4372 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4373 | } catch (ImsException e) { |
| 4374 | throw new ServiceSpecificException(e.getCode()); |
| 4375 | } finally { |
| 4376 | Binder.restoreCallingIdentity(identity); |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4381 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4382 | * @param subId The subscription to use to check the configuration. |
| 4383 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4384 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4385 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4386 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4387 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4388 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4391 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4392 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4393 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4394 | } catch (ImsException e) { |
| 4395 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4396 | } finally { |
| 4397 | Binder.restoreCallingIdentity(identity); |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4402 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4403 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4404 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4405 | final long identity = Binder.clearCallingIdentity(); |
| 4406 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4407 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4408 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4409 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4410 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4411 | } catch (ImsException e) { |
| 4412 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4413 | } finally { |
| 4414 | Binder.restoreCallingIdentity(identity); |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | @Override |
| 4419 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4420 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4421 | "setVoWiFiNonPersistent"); |
| 4422 | final long identity = Binder.clearCallingIdentity(); |
| 4423 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4424 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4425 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4426 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4427 | } catch (ImsException e) { |
| 4428 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
| 4431 | } |
| 4432 | } |
| 4433 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4434 | /** |
| 4435 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4436 | * @param subId The subscription to use to check the configuration. |
| 4437 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4438 | @Override |
| 4439 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4440 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4441 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4442 | final long identity = Binder.clearCallingIdentity(); |
| 4443 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4444 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4445 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4446 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4447 | } catch (ImsException e) { |
| 4448 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(identity); |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | @Override |
| 4455 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4456 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4457 | "setVoWiFiModeSetting"); |
| 4458 | final long identity = Binder.clearCallingIdentity(); |
| 4459 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4460 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4461 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4462 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4463 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4464 | } catch (ImsException e) { |
| 4465 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
| 4469 | } |
| 4470 | |
| 4471 | @Override |
| 4472 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4473 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4474 | final long identity = Binder.clearCallingIdentity(); |
| 4475 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4476 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4477 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4478 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4479 | } catch (ImsException e) { |
| 4480 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4481 | } finally { |
| 4482 | Binder.restoreCallingIdentity(identity); |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | @Override |
| 4487 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4489 | "setVoWiFiRoamingModeSetting"); |
| 4490 | final long identity = Binder.clearCallingIdentity(); |
| 4491 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4492 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4493 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4494 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4495 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4496 | } catch (ImsException e) { |
| 4497 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4498 | } finally { |
| 4499 | Binder.restoreCallingIdentity(identity); |
| 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | @Override |
| 4504 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4506 | "setRttCapabilityEnabled"); |
| 4507 | final long identity = Binder.clearCallingIdentity(); |
| 4508 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4509 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4510 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4511 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4512 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4513 | } catch (ImsException e) { |
| 4514 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4515 | } finally { |
| 4516 | Binder.restoreCallingIdentity(identity); |
| 4517 | } |
| 4518 | } |
| 4519 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4520 | /** |
| 4521 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4522 | * @param subId The subscription to use to check the configuration. |
| 4523 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4524 | @Override |
| 4525 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4526 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4527 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4528 | final long identity = Binder.clearCallingIdentity(); |
| 4529 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4530 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4531 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4532 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4533 | } catch (ImsException e) { |
| 4534 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
| 4537 | } |
| 4538 | } |
| 4539 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4540 | @Override |
| 4541 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4542 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4543 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4544 | final long identity = Binder.clearCallingIdentity(); |
| 4545 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4546 | if (!isImsAvailableOnDevice()) { |
| 4547 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4548 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4549 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4550 | int slotId = getSlotIndexOrException(subId); |
| 4551 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4552 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4553 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4554 | } catch (ImsException e) { |
| 4555 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4556 | } finally { |
| 4557 | Binder.restoreCallingIdentity(identity); |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | @Override |
| 4562 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4563 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4564 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4565 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4566 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4567 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4568 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4569 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4570 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4571 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4572 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4573 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4574 | + "is inactive, ignoring unregister."); |
| 4575 | // If the subscription is no longer active, just return, since the callback will already |
| 4576 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4577 | } finally { |
| 4578 | Binder.restoreCallingIdentity(identity); |
| 4579 | } |
| 4580 | } |
| 4581 | |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4582 | @Override |
| 4583 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4584 | IFeatureProvisioningCallback callback) { |
| 4585 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4586 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4587 | |
| 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4590 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4591 | } |
| 4592 | |
| 4593 | ImsProvisioningController.getInstance() |
| 4594 | .addFeatureProvisioningChangedCallback(subId, callback); |
| 4595 | |
| 4596 | Binder.restoreCallingIdentity(identity); |
| 4597 | } |
| 4598 | |
| 4599 | @Override |
| 4600 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4601 | IFeatureProvisioningCallback callback) { |
| 4602 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4603 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4604 | |
| 4605 | final long identity = Binder.clearCallingIdentity(); |
| 4606 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4607 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4608 | } |
| 4609 | |
| 4610 | ImsProvisioningController.getInstance() |
| 4611 | .removeFeatureProvisioningChangedCallback(subId, callback); |
| 4612 | |
| 4613 | Binder.restoreCallingIdentity(identity); |
| 4614 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4615 | |
| 4616 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4617 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4618 | message); |
| 4619 | } |
| 4620 | |
| 4621 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4622 | boolean isMmtelCapability) { |
| 4623 | Phone phone = getPhone(subId); |
| 4624 | if (phone == null) { |
| 4625 | loge("phone instance null for subid " + subId); |
| 4626 | return false; |
| 4627 | } |
| 4628 | if (isMmtelCapability) { |
| 4629 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4630 | return false; |
| 4631 | } |
| 4632 | } else { |
| 4633 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4634 | return false; |
| 4635 | } |
| 4636 | } |
| 4637 | return true; |
| 4638 | } |
| 4639 | |
| 4640 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4641 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4642 | boolean isProvisioned) { |
| 4643 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4644 | |
| 4645 | final long identity = Binder.clearCallingIdentity(); |
| 4646 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4647 | ImsProvisioningController.getInstance() |
| 4648 | .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
| 4649 | return; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4650 | } finally { |
| 4651 | Binder.restoreCallingIdentity(identity); |
| 4652 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | |
| 4656 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4657 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4658 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4659 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4660 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4661 | final long identity = Binder.clearCallingIdentity(); |
| 4662 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4663 | return ImsProvisioningController.getInstance() |
| 4664 | .getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
| 4668 | } |
| 4669 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4670 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4671 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4672 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4673 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4674 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4675 | final long identity = Binder.clearCallingIdentity(); |
| 4676 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4677 | ImsProvisioningController.getInstance() |
| 4678 | .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(identity); |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | @Override |
| 4685 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4686 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4687 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4688 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4691 | return ImsProvisioningController.getInstance() |
| 4692 | .getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4693 | |
| 4694 | } finally { |
| 4695 | Binder.restoreCallingIdentity(identity); |
| 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4700 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4701 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4702 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4703 | |
| 4704 | final long identity = Binder.clearCallingIdentity(); |
| 4705 | try { |
| 4706 | return ImsProvisioningController.getInstance() |
| 4707 | .isImsProvisioningRequiredForCapability(subId, capability, tech); |
| 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4710 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4714 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4715 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4716 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4717 | |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4718 | final long identity = Binder.clearCallingIdentity(); |
| 4719 | try { |
| 4720 | return ImsProvisioningController.getInstance() |
| 4721 | .isRcsProvisioningRequiredForCapability(subId, capability, tech); |
| 4722 | } finally { |
| 4723 | Binder.restoreCallingIdentity(identity); |
| 4724 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4728 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4729 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4734 | * carrier associated with the subscription id. |
| 4735 | */ |
| 4736 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4737 | int capability) { |
| 4738 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4739 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4740 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4741 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4742 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4743 | false); |
| 4744 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4745 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4746 | |
| 4747 | // First check to make sure that the capability requires provisioning. |
| 4748 | switch (capability) { |
| 4749 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4750 | // intentional fallthrough |
| 4751 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4752 | if (requireVoiceVtProvisioning) { |
| 4753 | // Voice and Video requires provisioning |
| 4754 | return true; |
| 4755 | } |
| 4756 | break; |
| 4757 | } |
| 4758 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4759 | if (requireUtProvisioning) { |
| 4760 | // UT requires provisioning |
| 4761 | return true; |
| 4762 | } |
| 4763 | break; |
| 4764 | } |
| 4765 | } |
| 4766 | return false; |
| 4767 | } |
| 4768 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4769 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4770 | int capability) { |
| 4771 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4772 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4773 | |
| 4774 | boolean requireRcsProvisioning = c.getBoolean( |
| 4775 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4776 | |
| 4777 | // First check to make sure that the capability requires provisioning. |
| 4778 | switch (capability) { |
| 4779 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4780 | // intentional fallthrough |
| 4781 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4782 | if (requireRcsProvisioning) { |
| 4783 | // OPTION or PRESENCE requires provisioning |
| 4784 | return true; |
| 4785 | } |
| 4786 | break; |
| 4787 | } |
| 4788 | } |
| 4789 | return false; |
| 4790 | } |
| 4791 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4792 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4793 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4794 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4795 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4796 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4797 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4798 | mApp, subId, "getImsProvisioningInt"); |
| 4799 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4800 | final long identity = Binder.clearCallingIdentity(); |
| 4801 | try { |
| 4802 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4803 | int slotId = getSlotIndex(subId); |
| 4804 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4805 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4806 | + subId + "' for key:" + key); |
| 4807 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4808 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4809 | |
| 4810 | int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key); |
| 4811 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4812 | return retVal; |
| 4813 | } |
| 4814 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4815 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4816 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4817 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4818 | + subId + "' for key:" + key); |
| 4819 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4820 | } finally { |
| 4821 | Binder.restoreCallingIdentity(identity); |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
| 4826 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4827 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4828 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4829 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4830 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4831 | mApp, subId, "getImsProvisioningString"); |
| 4832 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4833 | final long identity = Binder.clearCallingIdentity(); |
| 4834 | try { |
| 4835 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4836 | int slotId = getSlotIndex(subId); |
| 4837 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4838 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4839 | + subId + "' for key:" + key); |
| 4840 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4841 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4842 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4843 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4844 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4845 | + subId + "' for key:" + key); |
| 4846 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
| 4850 | } |
| 4851 | |
| 4852 | @Override |
| 4853 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4854 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4855 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4856 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4858 | "setImsProvisioningInt"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4859 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4860 | final long identity = Binder.clearCallingIdentity(); |
| 4861 | try { |
| 4862 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4863 | int slotId = getSlotIndex(subId); |
| 4864 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4865 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4866 | + subId + "' for key:" + key); |
| 4867 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4868 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4869 | |
| 4870 | int retVal = ImsProvisioningController.getInstance() |
| 4871 | .setProvisioningValue(subId, key, value); |
| 4872 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4873 | return retVal; |
| 4874 | } |
| 4875 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4876 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4877 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4878 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4879 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4880 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4881 | } finally { |
| 4882 | Binder.restoreCallingIdentity(identity); |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | @Override |
| 4887 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4888 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4889 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4890 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4892 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4893 | final long identity = Binder.clearCallingIdentity(); |
| 4894 | try { |
| 4895 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4896 | int slotId = getSlotIndex(subId); |
| 4897 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4898 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4899 | + subId + "' for key:" + key); |
| 4900 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4901 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4902 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4903 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4904 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4905 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4906 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
| 4909 | } |
| 4910 | } |
| 4911 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4912 | /** |
| 4913 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4914 | * for the given slot ID or no ImsResolver instance has been created. |
| 4915 | * @param slotId The slot ID that the IMS service is created for. |
| 4916 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4917 | */ |
| 4918 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4919 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4920 | ImsFeature.FEATURE_MMTEL)) { |
| 4921 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4922 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4923 | } |
| 4924 | } |
| 4925 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4926 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4927 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4928 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4929 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4930 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4931 | } |
| 4932 | return slotId; |
| 4933 | } |
| 4934 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4935 | private int getSlotIndex(int subId) { |
| 4936 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4937 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4938 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4939 | } |
| 4940 | return slotId; |
| 4941 | } |
| 4942 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4943 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4944 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4945 | */ |
| 4946 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4947 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4948 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4949 | try { |
| 4950 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4951 | } catch (SecurityException se) { |
| 4952 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 4953 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4954 | + Binder.getCallingUid()); |
| 4955 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4956 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4957 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4958 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4959 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4960 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4961 | mApp, subId, callingPackage, callingFeatureId, |
| 4962 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4963 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4964 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4965 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4966 | final long identity = Binder.clearCallingIdentity(); |
| 4967 | try { |
| 4968 | final Phone phone = getPhone(subId); |
| 4969 | if (phone != null) { |
| 4970 | return phone.getServiceState().getDataNetworkType(); |
| 4971 | } else { |
| 4972 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4973 | } |
| 4974 | } finally { |
| 4975 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4976 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | /** |
| 4980 | * Returns the data network type |
| 4981 | */ |
| 4982 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4983 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4984 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4985 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | /** |
| 4989 | * Returns the data network type for a subId |
| 4990 | */ |
| 4991 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4992 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4993 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 4994 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 4995 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 4996 | mApp, functionName)) { |
| 4997 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4998 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 4999 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5000 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5001 | } |
| 5002 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | final long identity = Binder.clearCallingIdentity(); |
| 5004 | try { |
| 5005 | final Phone phone = getPhone(subId); |
| 5006 | if (phone != null) { |
| 5007 | return phone.getServiceState().getDataNetworkType(); |
| 5008 | } else { |
| 5009 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5010 | } |
| 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5013 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5017 | * Returns the Voice network type for a subId |
| 5018 | */ |
| 5019 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5020 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5021 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5022 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5023 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5024 | mApp, functionName)) { |
| 5025 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5026 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5027 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5028 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5031 | final long identity = Binder.clearCallingIdentity(); |
| 5032 | try { |
| 5033 | final Phone phone = getPhone(subId); |
| 5034 | if (phone != null) { |
| 5035 | return phone.getServiceState().getVoiceNetworkType(); |
| 5036 | } else { |
| 5037 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5038 | } |
| 5039 | } finally { |
| 5040 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5041 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | /** |
| 5045 | * @return true if a ICC card is present |
| 5046 | */ |
| 5047 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5048 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5049 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5050 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5054 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5055 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5056 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5057 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
| 5060 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5061 | if (phone != null) { |
| 5062 | return phone.getIccCard().hasIccCard(); |
| 5063 | } else { |
| 5064 | return false; |
| 5065 | } |
| 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5068 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
| 5072 | * Return if the current radio is LTE on CDMA. This |
| 5073 | * is a tri-state return value as for a period of time |
| 5074 | * the mode may be unknown. |
| 5075 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5076 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5077 | * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE} |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5078 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5079 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5080 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5081 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5082 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5083 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5086 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5087 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5088 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5089 | try { |
| 5090 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5091 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5092 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5093 | } |
| 5094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | final long identity = Binder.clearCallingIdentity(); |
| 5096 | try { |
| 5097 | final Phone phone = getPhone(subId); |
| 5098 | if (phone == null) { |
| 5099 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5100 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5101 | return TelephonyProperties.lte_on_cdma_device() |
| 5102 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5103 | } |
| 5104 | } finally { |
| 5105 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5106 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5107 | } |
| 5108 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5109 | /** |
| 5110 | * {@hide} |
| 5111 | * Returns Default subId, 0 in the case of single standby. |
| 5112 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5113 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5114 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5117 | private int getSlotForDefaultSubscription() { |
| 5118 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5119 | } |
| 5120 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5121 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5122 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5123 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5124 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5125 | private boolean isActiveSubscription(int subId) { |
| 5126 | return mSubscriptionController.isActiveSubId(subId); |
| 5127 | } |
| 5128 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5129 | /** |
| 5130 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5131 | */ |
| 5132 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | final long identity = Binder.clearCallingIdentity(); |
| 5134 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5135 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5137 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
| 5140 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | /** |
| 5144 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5145 | */ |
| 5146 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
| 5149 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5150 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5151 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5152 | } finally { |
| 5153 | Binder.restoreCallingIdentity(identity); |
| 5154 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5155 | } |
| 5156 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5157 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5158 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5159 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5160 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5161 | |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5162 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5163 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5164 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5165 | if (phoneId == -1) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5166 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5167 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5168 | } |
| 5169 | return PhoneFactory.getPhone(phoneId); |
| 5170 | } |
| 5171 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5172 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5173 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5174 | @NonNull IccLogicalChannelRequest request) { |
| 5175 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5176 | /*message=*/ "iccOpenLogicalChannel"); |
| 5177 | |
| 5178 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5179 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5180 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5181 | |
| 5182 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5183 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5184 | |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5185 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5186 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5187 | Phone phone; |
| 5188 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5189 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5190 | mApp, request.subId, message); |
| 5191 | phone = getPhoneFromSubId(request.subId); |
| 5192 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5193 | enforceModifyPermission(); |
| 5194 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5195 | } else { |
| 5196 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5197 | } |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5198 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5202 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | final long identity = Binder.clearCallingIdentity(); |
| 5204 | try { |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5205 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5206 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5207 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5208 | .getContext().getPackageManager()); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5209 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5210 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | loge("The calling package is not allowed to access ISD-R."); |
| 5212 | throw new SecurityException( |
| 5213 | "The calling package is not allowed to access ISD-R."); |
| 5214 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5215 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5216 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5218 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5219 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | return response; |
| 5221 | } finally { |
| 5222 | Binder.restoreCallingIdentity(identity); |
| 5223 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | @Override |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5227 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5228 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5229 | /*message=*/"iccCloseLogicalChannel"); |
| 5230 | |
| 5231 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5232 | |
| 5233 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5234 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5235 | |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5236 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5237 | IccLogicalChannelRequest request) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5240 | if (request.channel < 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | return false; |
| 5242 | } |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5243 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5244 | null /* workSource */); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame^] | 5245 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | return success; |
| 5247 | } finally { |
| 5248 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5249 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5253 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5254 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5255 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5256 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5257 | if (DBG) { |
| 5258 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5259 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5260 | + p3 + " data=" + data); |
| 5261 | } |
| 5262 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5263 | command, p1, p2, p3, data); |
| 5264 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5265 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5266 | @Override |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5267 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5268 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5269 | enforceModifyPermission(); |
| 5270 | if (DBG) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5271 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5272 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5273 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5274 | } |
| 5275 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5276 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5277 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5281 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5282 | final long identity = Binder.clearCallingIdentity(); |
| 5283 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5284 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | return ""; |
| 5286 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5289 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5290 | null /* workSource */); |
| 5291 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | // Append the returned status code to the end of the response payload. |
| 5294 | String s = Integer.toHexString( |
| 5295 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5296 | if (response.payload != null) { |
| 5297 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5298 | } |
| 5299 | return s; |
| 5300 | } finally { |
| 5301 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5302 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5303 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5304 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5305 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5306 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5307 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5309 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5310 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5311 | if (DBG) { |
| 5312 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5313 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5314 | } |
| 5315 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5316 | cla, command, p1, p2, p3, data); |
| 5317 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5318 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5319 | @Override |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5320 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5321 | String callingPackage, int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5322 | enforceModifyPermission(); |
| 5323 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5324 | if (DBG) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5325 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5326 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5327 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5331 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5332 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5336 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5337 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | final long identity = Binder.clearCallingIdentity(); |
| 5339 | try { |
| 5340 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5341 | && TextUtils.equals(ISDR_AID, data)) { |
| 5342 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5343 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5344 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | if (bestComponent == null |
| 5346 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5347 | loge("The calling package is not allowed to select ISD-R."); |
| 5348 | throw new SecurityException( |
| 5349 | "The calling package is not allowed to select ISD-R."); |
| 5350 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5351 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5352 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5354 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5355 | null /* workSource */); |
| 5356 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | // Append the returned status code to the end of the response payload. |
| 5359 | String s = Integer.toHexString( |
| 5360 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5361 | if (response.payload != null) { |
| 5362 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5363 | } |
| 5364 | return s; |
| 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5367 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5371 | public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5372 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5374 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
| 5378 | if (DBG) { |
| 5379 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5380 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5381 | } |
| 5382 | |
| 5383 | IccIoResult response = |
| 5384 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5385 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5386 | subId); |
| 5387 | |
| 5388 | if (DBG) { |
| 5389 | log("Exchange SIM_IO [R]" + response); |
| 5390 | } |
| 5391 | |
| 5392 | byte[] result = null; |
| 5393 | int length = 2; |
| 5394 | if (response.payload != null) { |
| 5395 | length = 2 + response.payload.length; |
| 5396 | result = new byte[length]; |
| 5397 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5398 | } else { |
| 5399 | result = new byte[length]; |
| 5400 | } |
| 5401 | |
| 5402 | result[length - 1] = (byte) response.sw2; |
| 5403 | result[length - 2] = (byte) response.sw1; |
| 5404 | return result; |
| 5405 | } finally { |
| 5406 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5407 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5410 | /** |
| 5411 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5412 | * on a particular subscription |
| 5413 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5414 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5415 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5417 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5418 | return null; |
| 5419 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5420 | |
| 5421 | final long identity = Binder.clearCallingIdentity(); |
| 5422 | try { |
| 5423 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5424 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5425 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5426 | return null; |
| 5427 | } |
| 5428 | Object response = sendRequest( |
| 5429 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5430 | if (response instanceof String[]) { |
| 5431 | return (String[]) response; |
| 5432 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5433 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5435 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5436 | } finally { |
| 5437 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5438 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5439 | } |
| 5440 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5441 | /** |
| 5442 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5443 | * subscription. |
| 5444 | * |
| 5445 | * @param subId the id of the subscription. |
| 5446 | * @param appType the uicc app type, must be USIM or SIM. |
| 5447 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5448 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5449 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5450 | * @return number of fplmns that is successfully written to the SIM. |
| 5451 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5452 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5453 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5455 | mApp, subId, "setForbiddenPlmns"); |
| 5456 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5457 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5458 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5459 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5460 | } |
| 5461 | if (fplmns == null) { |
| 5462 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5463 | } |
| 5464 | for (String fplmn : fplmns) { |
| 5465 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5466 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5467 | } |
| 5468 | } |
| 5469 | final long identity = Binder.clearCallingIdentity(); |
| 5470 | try { |
| 5471 | Object response = sendRequest( |
| 5472 | CMD_SET_FORBIDDEN_PLMNS, |
| 5473 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5474 | subId); |
| 5475 | return (int) response; |
| 5476 | } finally { |
| 5477 | Binder.restoreCallingIdentity(identity); |
| 5478 | } |
| 5479 | } |
| 5480 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5481 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5482 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5483 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5484 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5485 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | final long identity = Binder.clearCallingIdentity(); |
| 5487 | try { |
| 5488 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5489 | if (response.payload == null) { |
| 5490 | return ""; |
| 5491 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5492 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5493 | // Append the returned status code to the end of the response payload. |
| 5494 | String s = Integer.toHexString( |
| 5495 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5496 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5497 | return s; |
| 5498 | } finally { |
| 5499 | Binder.restoreCallingIdentity(identity); |
| 5500 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5501 | } |
| 5502 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5503 | /** |
| 5504 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5505 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5506 | * |
| 5507 | * @param itemID the ID of the item to read |
| 5508 | * @return the NV item as a String, or null on error. |
| 5509 | */ |
| 5510 | @Override |
| 5511 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5512 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5514 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 | |
| 5516 | final long identity = Binder.clearCallingIdentity(); |
| 5517 | try { |
| 5518 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5519 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5520 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5521 | return value; |
| 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
| 5524 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5529 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5530 | * |
| 5531 | * @param itemID the ID of the item to read |
| 5532 | * @param itemValue the value to write, as a String |
| 5533 | * @return true on success; false on any failure |
| 5534 | */ |
| 5535 | @Override |
| 5536 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5537 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5539 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5540 | |
| 5541 | final long identity = Binder.clearCallingIdentity(); |
| 5542 | try { |
| 5543 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5544 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5545 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5547 | return success; |
| 5548 | } finally { |
| 5549 | Binder.restoreCallingIdentity(identity); |
| 5550 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | /** |
| 5554 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5555 | * Used for device configuration by some CDMA operators. |
| 5556 | * |
| 5557 | * @param preferredRoamingList byte array containing the new PRL |
| 5558 | * @return true on success; false on any failure |
| 5559 | */ |
| 5560 | @Override |
| 5561 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5562 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5563 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | |
| 5565 | final long identity = Binder.clearCallingIdentity(); |
| 5566 | try { |
| 5567 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5568 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5569 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5570 | return success; |
| 5571 | } finally { |
| 5572 | Binder.restoreCallingIdentity(identity); |
| 5573 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5577 | * Rollback modem configurations to factory default except some config which are in whitelist. |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5578 | * Used for device configuration by some CDMA operators. |
| 5579 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5580 | * @param slotIndex - device slot. |
| 5581 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5582 | * @return true on success; false on any failure |
| 5583 | */ |
| 5584 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5585 | public boolean resetModemConfig(int slotIndex) { |
| 5586 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5587 | if (phone != null) { |
| 5588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5589 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
| 5593 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5594 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5595 | return success; |
| 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5599 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5600 | return false; |
| 5601 | } |
| 5602 | |
| 5603 | /** |
| 5604 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5605 | * |
| 5606 | * @param slotIndex - device slot. |
| 5607 | * |
| 5608 | * @return true on success; false on any failure |
| 5609 | */ |
| 5610 | @Override |
| 5611 | public boolean rebootModem(int slotIndex) { |
| 5612 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5613 | if (phone != null) { |
| 5614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5615 | mApp, phone.getSubId(), "rebootModem"); |
| 5616 | |
| 5617 | final long identity = Binder.clearCallingIdentity(); |
| 5618 | try { |
| 5619 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5620 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5621 | return success; |
| 5622 | } finally { |
| 5623 | Binder.restoreCallingIdentity(identity); |
| 5624 | } |
| 5625 | } |
| 5626 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5627 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5628 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5629 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5630 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5631 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5632 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5633 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5634 | return new String[0]; |
| 5635 | } |
| 5636 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | final long identity = Binder.clearCallingIdentity(); |
| 5638 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5639 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | } finally { |
| 5641 | Binder.restoreCallingIdentity(identity); |
| 5642 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5643 | } |
| 5644 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5645 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5646 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5647 | * {@link #disableIms(int)}. |
| 5648 | * @param slotIndex device slot. |
| 5649 | */ |
| 5650 | public void resetIms(int slotIndex) { |
| 5651 | enforceModifyPermission(); |
| 5652 | |
| 5653 | final long identity = Binder.clearCallingIdentity(); |
| 5654 | try { |
| 5655 | if (mImsResolver == null) { |
| 5656 | // may happen if the does not support IMS. |
| 5657 | return; |
| 5658 | } |
| 5659 | mImsResolver.disableIms(slotIndex); |
| 5660 | mImsResolver.enableIms(slotIndex); |
| 5661 | } finally { |
| 5662 | Binder.restoreCallingIdentity(identity); |
| 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5667 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5668 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5669 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5670 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5671 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | |
| 5673 | final long identity = Binder.clearCallingIdentity(); |
| 5674 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5675 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5676 | // may happen if the device does not support IMS. |
| 5677 | return; |
| 5678 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5679 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | } finally { |
| 5681 | Binder.restoreCallingIdentity(identity); |
| 5682 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5686 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5687 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5688 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5689 | public void disableIms(int slotId) { |
| 5690 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5691 | |
| 5692 | final long identity = Binder.clearCallingIdentity(); |
| 5693 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5694 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5695 | // may happen if the device does not support IMS. |
| 5696 | return; |
| 5697 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5698 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | } finally { |
| 5700 | Binder.restoreCallingIdentity(identity); |
| 5701 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5705 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5706 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5707 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5708 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5709 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5710 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 | |
| 5712 | final long identity = Binder.clearCallingIdentity(); |
| 5713 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5714 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5715 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5716 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5717 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5718 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
| 5721 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5722 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5723 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5724 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5725 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5726 | @Override |
| 5727 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5728 | enforceModifyPermission(); |
| 5729 | |
| 5730 | final long identity = Binder.clearCallingIdentity(); |
| 5731 | try { |
| 5732 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5733 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5734 | } finally { |
| 5735 | Binder.restoreCallingIdentity(identity); |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5740 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5741 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5742 | */ |
| 5743 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5744 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | |
| 5746 | final long identity = Binder.clearCallingIdentity(); |
| 5747 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5748 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5749 | // may happen if the device does not support IMS. |
| 5750 | return null; |
| 5751 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5752 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5753 | } finally { |
| 5754 | Binder.restoreCallingIdentity(identity); |
| 5755 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5756 | } |
| 5757 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5758 | /** |
| 5759 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5760 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5761 | */ |
| 5762 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5763 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | |
| 5765 | final long identity = Binder.clearCallingIdentity(); |
| 5766 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5767 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5768 | // may happen if the device does not support IMS. |
| 5769 | return null; |
| 5770 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5771 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
| 5774 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5775 | } |
| 5776 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5777 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5778 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5779 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5780 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5781 | * @param isCarrierService true if the ImsService is the carrier override, false if the |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5782 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5783 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5784 | * @param packageName The name of the package that the current configuration will be replaced |
| 5785 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5786 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5787 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5788 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5789 | int[] featureTypes, String packageName) { |
| 5790 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5791 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5793 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5794 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5796 | final long identity = Binder.clearCallingIdentity(); |
| 5797 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5798 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5799 | // may happen if the device does not support IMS. |
| 5800 | return false; |
| 5801 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5802 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5803 | for (int featureType : featureTypes) { |
| 5804 | featureConfig.put(featureType, packageName); |
| 5805 | } |
| 5806 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5807 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5808 | } finally { |
| 5809 | Binder.restoreCallingIdentity(identity); |
| 5810 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5814 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5815 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5816 | * |
| 5817 | * This should only be used for testing. |
| 5818 | * |
| 5819 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5820 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5821 | */ |
| 5822 | @Override |
| 5823 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5824 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5825 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5826 | "clearCarrierImsServiceOverride"); |
| 5827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5828 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5829 | "clearCarrierImsServiceOverride"); |
| 5830 | |
| 5831 | final long identity = Binder.clearCallingIdentity(); |
| 5832 | try { |
| 5833 | if (mImsResolver == null) { |
| 5834 | // may happen if the device does not support IMS. |
| 5835 | return false; |
| 5836 | } |
| 5837 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5838 | } finally { |
| 5839 | Binder.restoreCallingIdentity(identity); |
| 5840 | } |
| 5841 | } |
| 5842 | |
| 5843 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5844 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5845 | * |
| 5846 | * @param slotId The slot that the ImsService is associated with. |
| 5847 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5848 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5849 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5850 | * @return the package name of the ImsService configuration. |
| 5851 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5852 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5853 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5854 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5855 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5856 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5857 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5858 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5859 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5860 | final long identity = Binder.clearCallingIdentity(); |
| 5861 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5862 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5863 | // may happen if the device does not support IMS. |
| 5864 | return ""; |
| 5865 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5866 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5867 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5868 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5869 | } finally { |
| 5870 | Binder.restoreCallingIdentity(identity); |
| 5871 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5874 | /** |
| 5875 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5876 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5877 | * @param callback A callback with an integer containing the |
| 5878 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5879 | */ |
| 5880 | @Override |
| 5881 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5882 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5883 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5884 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5885 | "IMS not available on device."); |
| 5886 | } |
| 5887 | final long token = Binder.clearCallingIdentity(); |
| 5888 | try { |
| 5889 | int slotId = getSlotIndex(subId); |
| 5890 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5891 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5892 | + subId + "'"); |
| 5893 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5894 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5895 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5896 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5897 | try { |
| 5898 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5899 | } catch (RemoteException e) { |
| 5900 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5901 | + "Ignore"); |
| 5902 | } |
| 5903 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5904 | } catch (ImsException e) { |
| 5905 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5906 | } finally { |
| 5907 | Binder.restoreCallingIdentity(token); |
| 5908 | } |
| 5909 | } |
| 5910 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5911 | /** |
| 5912 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5913 | */ |
| 5914 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5915 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | |
| 5917 | final long identity = Binder.clearCallingIdentity(); |
| 5918 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5919 | // NOTE: Before S, this method only set the default phone. |
| 5920 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5921 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5922 | phone.setImsRegistrationState(registered); |
| 5923 | } |
| 5924 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | } finally { |
| 5926 | Binder.restoreCallingIdentity(identity); |
| 5927 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5931 | * Set the network selection mode to automatic. |
| 5932 | * |
| 5933 | */ |
| 5934 | @Override |
| 5935 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5937 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5938 | |
| 5939 | final long identity = Binder.clearCallingIdentity(); |
| 5940 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5941 | if (!isActiveSubscription(subId)) { |
| 5942 | return; |
| 5943 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5945 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5946 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | } finally { |
| 5948 | Binder.restoreCallingIdentity(identity); |
| 5949 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5950 | } |
| 5951 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5952 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5953 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5954 | * |
| 5955 | * @param subId the id of the subscription. |
| 5956 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5957 | * the operator to attach to. |
| 5958 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5959 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5960 | * normal network selection next time. |
| 5961 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5962 | */ |
| 5963 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5964 | public boolean setNetworkSelectionModeManual( |
| 5965 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5967 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5968 | |
| 5969 | if (!isActiveSubscription(subId)) { |
| 5970 | return false; |
| 5971 | } |
| 5972 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5973 | final long identity = Binder.clearCallingIdentity(); |
| 5974 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5975 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5976 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5977 | if (DBG) { |
| 5978 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5979 | + " operator: " + operatorInfo); |
| 5980 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5982 | } finally { |
| 5983 | Binder.restoreCallingIdentity(identity); |
| 5984 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5985 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5986 | /** |
| 5987 | * Get the manual network selection |
| 5988 | * |
| 5989 | * @param subId the id of the subscription. |
| 5990 | * |
| 5991 | * @return the previously saved user selected PLMN |
| 5992 | */ |
| 5993 | @Override |
| 5994 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5995 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5996 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5997 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5998 | |
| 5999 | final long identity = Binder.clearCallingIdentity(); |
| 6000 | try { |
| 6001 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6002 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | final Phone phone = getPhone(subId); |
| 6006 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6007 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6008 | } |
| 6009 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6010 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6011 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6012 | } finally { |
| 6013 | Binder.restoreCallingIdentity(identity); |
| 6014 | } |
| 6015 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6016 | |
| 6017 | /** |
| 6018 | * Scans for available networks. |
| 6019 | */ |
| 6020 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6021 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6022 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6023 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6024 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6025 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6026 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6027 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6028 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6029 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6030 | .setCallingPid(Binder.getCallingPid()) |
| 6031 | .setCallingUid(Binder.getCallingUid()) |
| 6032 | .setMethod("getCellNetworkScanResults") |
| 6033 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6034 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6035 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6036 | .build()); |
| 6037 | switch (locationResult) { |
| 6038 | case DENIED_HARD: |
| 6039 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6040 | case DENIED_SOFT: |
| 6041 | return null; |
| 6042 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6043 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6044 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6045 | try { |
| 6046 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6047 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6048 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | } finally { |
| 6050 | Binder.restoreCallingIdentity(identity); |
| 6051 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6055 | * Get the call forwarding info, given the call forwarding reason. |
| 6056 | */ |
| 6057 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6058 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6059 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6060 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6061 | long identity = Binder.clearCallingIdentity(); |
| 6062 | try { |
| 6063 | if (DBG) { |
| 6064 | log("getCallForwarding: subId " + subId |
| 6065 | + " callForwardingReason" + callForwardingReason); |
| 6066 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6067 | |
| 6068 | Phone phone = getPhone(subId); |
| 6069 | if (phone == null) { |
| 6070 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6071 | callback.onError( |
| 6072 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6073 | } catch (RemoteException e) { |
| 6074 | // ignore |
| 6075 | } |
| 6076 | return; |
| 6077 | } |
| 6078 | |
| 6079 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6080 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6081 | @Override |
| 6082 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6083 | try { |
| 6084 | callback.onCallForwardingInfoAvailable(info); |
| 6085 | } catch (RemoteException e) { |
| 6086 | // ignore |
| 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | @Override |
| 6091 | public void onError(int error) { |
| 6092 | try { |
| 6093 | callback.onError(error); |
| 6094 | } catch (RemoteException e) { |
| 6095 | // ignore |
| 6096 | } |
| 6097 | } |
| 6098 | }); |
| 6099 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6100 | } finally { |
| 6101 | Binder.restoreCallingIdentity(identity); |
| 6102 | } |
| 6103 | } |
| 6104 | |
| 6105 | /** |
| 6106 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6107 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6108 | */ |
| 6109 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6110 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6111 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6112 | enforceModifyPermission(); |
| 6113 | long identity = Binder.clearCallingIdentity(); |
| 6114 | try { |
| 6115 | if (DBG) { |
| 6116 | log("setCallForwarding: subId " + subId |
| 6117 | + " callForwardingInfo" + callForwardingInfo); |
| 6118 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6119 | |
| 6120 | Phone phone = getPhone(subId); |
| 6121 | if (phone == null) { |
| 6122 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6123 | callback.accept( |
| 6124 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6125 | } catch (RemoteException e) { |
| 6126 | // ignore |
| 6127 | } |
| 6128 | return; |
| 6129 | } |
| 6130 | |
| 6131 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6132 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6133 | |
| 6134 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6135 | } finally { |
| 6136 | Binder.restoreCallingIdentity(identity); |
| 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6141 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6142 | */ |
| 6143 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6144 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6145 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6146 | long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6148 | Phone phone = getPhone(subId); |
| 6149 | if (phone == null) { |
| 6150 | try { |
| 6151 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6152 | } catch (RemoteException e) { |
| 6153 | // ignore |
| 6154 | } |
| 6155 | return; |
| 6156 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6157 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6158 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6159 | boolean requireUssd = c.getBoolean( |
| 6160 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6161 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6162 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6163 | if (requireUssd) { |
| 6164 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6165 | getSubscriptionCarrierId(subId)); |
| 6166 | String newUssdCommand = ""; |
| 6167 | try { |
| 6168 | newUssdCommand = carrierXmlParser.getFeature( |
| 6169 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6170 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6171 | } catch (NullPointerException e) { |
| 6172 | loge("Failed to generate USSD number" + e); |
| 6173 | } |
| 6174 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6175 | mMainThreadHandler, callback, carrierXmlParser, |
| 6176 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6177 | final String ussdCommand = newUssdCommand; |
| 6178 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6179 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6180 | }); |
| 6181 | } else { |
| 6182 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6183 | callback::accept); |
| 6184 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6185 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6186 | } finally { |
| 6187 | Binder.restoreCallingIdentity(identity); |
| 6188 | } |
| 6189 | } |
| 6190 | |
| 6191 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6192 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6193 | */ |
| 6194 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6195 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6196 | enforceModifyPermission(); |
| 6197 | long identity = Binder.clearCallingIdentity(); |
| 6198 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6199 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6200 | |
| 6201 | Phone phone = getPhone(subId); |
| 6202 | if (phone == null) { |
| 6203 | try { |
| 6204 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6205 | } catch (RemoteException e) { |
| 6206 | // ignore |
| 6207 | } |
| 6208 | return; |
| 6209 | } |
| 6210 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6211 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6212 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6213 | boolean requireUssd = c.getBoolean( |
| 6214 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6215 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6216 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6217 | if (requireUssd) { |
| 6218 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6219 | getSubscriptionCarrierId(subId)); |
| 6220 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6221 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6222 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6223 | String newUssdCommand = ""; |
| 6224 | try { |
| 6225 | newUssdCommand = carrierXmlParser.getFeature( |
| 6226 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6227 | .makeCommand(ssAction, null); |
| 6228 | } catch (NullPointerException e) { |
| 6229 | loge("Failed to generate USSD number" + e); |
| 6230 | } |
| 6231 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6232 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6233 | final String ussdCommand = newUssdCommand; |
| 6234 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6235 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6236 | }); |
| 6237 | } else { |
| 6238 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6239 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6240 | |
| 6241 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6242 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6243 | } finally { |
| 6244 | Binder.restoreCallingIdentity(identity); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6249 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6250 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6251 | * @param subId id of the subscription |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6252 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6253 | * location related information which will be sent if the caller already possess |
| 6254 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6255 | * @param request contains the radio access networks with bands/channels to scan |
| 6256 | * @param messenger callback messenger for scan results or errors |
| 6257 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6258 | * @return the id of the requested scan which can be used to stop the scan. |
| 6259 | */ |
| 6260 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6261 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6262 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6263 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6265 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6266 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6267 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6268 | if (!renounceFineLocationAccess) { |
| 6269 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6270 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6271 | .setCallingPackage(callingPackage) |
| 6272 | .setCallingFeatureId(callingFeatureId) |
| 6273 | .setCallingPid(Binder.getCallingPid()) |
| 6274 | .setCallingUid(Binder.getCallingUid()) |
| 6275 | .setMethod("requestNetworkScan") |
| 6276 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6277 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6278 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6279 | .build()); |
| 6280 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6281 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6282 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6283 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6284 | if (e != null) { |
| 6285 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6286 | throw e; |
| 6287 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6288 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6289 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6290 | } |
| 6291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6293 | int callingUid = Binder.getCallingUid(); |
| 6294 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6295 | final long identity = Binder.clearCallingIdentity(); |
| 6296 | try { |
| 6297 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6298 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6299 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6300 | } finally { |
| 6301 | Binder.restoreCallingIdentity(identity); |
| 6302 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6303 | } |
| 6304 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6305 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6306 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6307 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6308 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6309 | boolean hasNetworkScanPermission = |
| 6310 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6311 | == PERMISSION_GRANTED; |
| 6312 | |
| 6313 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6314 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6315 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6319 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6320 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6321 | return new SecurityException("Specific channels must not be" |
| 6322 | + " scanned without location access."); |
| 6323 | } |
| 6324 | } |
| 6325 | } |
| 6326 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6327 | return null; |
| 6328 | } |
| 6329 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6330 | /** |
| 6331 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6332 | * |
| 6333 | * @param subId id of the subscription |
| 6334 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6335 | */ |
| 6336 | @Override |
| 6337 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6339 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6340 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6341 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6342 | final long identity = Binder.clearCallingIdentity(); |
| 6343 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6344 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | } finally { |
| 6346 | Binder.restoreCallingIdentity(identity); |
| 6347 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6351 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6352 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6353 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6354 | */ |
| 6355 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6356 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6357 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6358 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6359 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6363 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6364 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6365 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6366 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6367 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
| 6370 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6374 | * Get the allowed network types for certain reason. |
| 6375 | * |
| 6376 | * @param subId the id of the subscription. |
| 6377 | * @param reason the reason the allowed network type change is taking place |
| 6378 | * @return the allowed network types. |
| 6379 | */ |
| 6380 | @Override |
| 6381 | public long getAllowedNetworkTypesForReason(int subId, |
| 6382 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6383 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6384 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6385 | final long identity = Binder.clearCallingIdentity(); |
| 6386 | try { |
| 6387 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6388 | } finally { |
| 6389 | Binder.restoreCallingIdentity(identity); |
| 6390 | } |
| 6391 | } |
| 6392 | |
| 6393 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6394 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6395 | * @param subId subscription id of the sim card |
| 6396 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6397 | * This can be passed following states |
| 6398 | * <ol> |
| 6399 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6400 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6401 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6402 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6403 | * </ol> |
| 6404 | * @return operation result. |
| 6405 | */ |
| 6406 | @Override |
| 6407 | public int setNrDualConnectivityState(int subId, |
| 6408 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6409 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6410 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6411 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6412 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6413 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6414 | } |
| 6415 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6416 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6417 | final long identity = Binder.clearCallingIdentity(); |
| 6418 | try { |
| 6419 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6420 | nrDualConnectivityState, subId, |
| 6421 | workSource); |
| 6422 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6423 | return result; |
| 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | /** |
| 6430 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6431 | * @return true if dual connectivity is enabled else false |
| 6432 | */ |
| 6433 | @Override |
| 6434 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6435 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6436 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6437 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6438 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6439 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6440 | return false; |
| 6441 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6442 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6443 | final long identity = Binder.clearCallingIdentity(); |
| 6444 | try { |
| 6445 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6446 | null, subId, workSource); |
| 6447 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6448 | return isEnabled; |
| 6449 | } finally { |
| 6450 | Binder.restoreCallingIdentity(identity); |
| 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6455 | * Set the allowed network types of the device and |
| 6456 | * provide the reason triggering the allowed network change. |
| 6457 | * |
| 6458 | * @param subId the id of the subscription. |
| 6459 | * @param reason the reason the allowed network type change is taking place |
| 6460 | * @param allowedNetworkTypes the allowed network types. |
| 6461 | * @return true on success; false on any failure. |
| 6462 | */ |
| 6463 | @Override |
| 6464 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6465 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6466 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6467 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6468 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6469 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6470 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6471 | return false; |
| 6472 | } |
| 6473 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6474 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6475 | return false; |
| 6476 | } |
| 6477 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6478 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6479 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6480 | |
| 6481 | |
| 6482 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6483 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6484 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6485 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6486 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6487 | final long identity = Binder.clearCallingIdentity(); |
| 6488 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6489 | Boolean success = (Boolean) sendRequest( |
| 6490 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6491 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6492 | |
| 6493 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6494 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6495 | } finally { |
| 6496 | Binder.restoreCallingIdentity(identity); |
| 6497 | } |
| 6498 | } |
| 6499 | |
| 6500 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6501 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6502 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6503 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6504 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6505 | * @hide |
| 6506 | */ |
| 6507 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6508 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6509 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6510 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6511 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6512 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6513 | if (phone != null) { |
| 6514 | return phone.hasMatchedTetherApnSetting(); |
| 6515 | } else { |
| 6516 | return false; |
| 6517 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6518 | } finally { |
| 6519 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6520 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6521 | } |
| 6522 | |
| 6523 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6524 | * Get the user enabled state of Mobile Data. |
| 6525 | * |
| 6526 | * TODO: remove and use isUserDataEnabled. |
| 6527 | * This can't be removed now because some vendor codes |
| 6528 | * calls through ITelephony directly while they should |
| 6529 | * use TelephonyManager. |
| 6530 | * |
| 6531 | * @return true on enabled |
| 6532 | */ |
| 6533 | @Override |
| 6534 | public boolean getDataEnabled(int subId) { |
| 6535 | return isUserDataEnabled(subId); |
| 6536 | } |
| 6537 | |
| 6538 | /** |
| 6539 | * Get whether mobile data is enabled per user setting. |
| 6540 | * |
| 6541 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6542 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6543 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6544 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6545 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6546 | * |
| 6547 | * @return {@code true} if data is enabled else {@code false} |
| 6548 | */ |
| 6549 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6550 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6551 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6552 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6553 | try { |
| 6554 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6555 | functionName); |
| 6556 | } catch (Exception e) { |
| 6557 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6558 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6559 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6561 | mApp, subId, functionName); |
| 6562 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6563 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | |
| 6565 | final long identity = Binder.clearCallingIdentity(); |
| 6566 | try { |
| 6567 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6568 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6569 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6570 | if (phone != null) { |
| 6571 | boolean retVal = phone.isUserDataEnabled(); |
| 6572 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6573 | return retVal; |
| 6574 | } else { |
| 6575 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6576 | return false; |
| 6577 | } |
| 6578 | } finally { |
| 6579 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6580 | } |
| 6581 | } |
| 6582 | |
| 6583 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6584 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6585 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6586 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6587 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6588 | * @return {@code true} if the overall data connection is capable; {@code false} if not. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6589 | */ |
| 6590 | @Override |
| 6591 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6592 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6593 | try { |
| 6594 | try { |
| 6595 | mApp.enforceCallingOrSelfPermission( |
| 6596 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6597 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6598 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6599 | try { |
| 6600 | mApp.enforceCallingOrSelfPermission( |
| 6601 | android.Manifest.permission.READ_PHONE_STATE, |
| 6602 | functionName); |
| 6603 | } catch (Exception e2) { |
| 6604 | mApp.enforceCallingOrSelfPermission( |
| 6605 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6606 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6607 | } |
| 6608 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6609 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6610 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6611 | |
| 6612 | final long identity = Binder.clearCallingIdentity(); |
| 6613 | try { |
| 6614 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6615 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6616 | if (phone != null) { |
Jack Yu | 3fb3a6b | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6617 | boolean retVal; |
| 6618 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 8619e16 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6619 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 3fb3a6b | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6620 | } else { |
| 6621 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6622 | } |
| 6623 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6624 | return retVal; |
| 6625 | } else { |
| 6626 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6627 | return false; |
| 6628 | } |
| 6629 | } finally { |
| 6630 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6631 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6632 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6633 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6634 | /** |
| 6635 | * Check if data is enabled for a specific reason |
| 6636 | * @param subId Subscription index |
| 6637 | * @param reason the reason the data enable change is taking place |
| 6638 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6639 | */ |
| 6640 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6641 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6642 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6643 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6644 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6645 | try { |
| 6646 | mApp.enforceCallingOrSelfPermission( |
| 6647 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6648 | functionName); |
| 6649 | } catch (Exception e) { |
| 6650 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6651 | functionName); |
| 6652 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6653 | } catch (Exception e) { |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6654 | try { |
| 6655 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6656 | functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6657 | } catch (Exception e2) { |
| 6658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6659 | mApp, subId, functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6660 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | |
| 6664 | final long identity = Binder.clearCallingIdentity(); |
| 6665 | try { |
| 6666 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6667 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6668 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6669 | + " reason=" + reason); |
| 6670 | } |
| 6671 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6672 | if (phone != null) { |
| 6673 | boolean retVal; |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6674 | if (phone.isUsingNewDataStack()) { |
| 6675 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6676 | } else { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6677 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6678 | retVal = phone.isUserDataEnabled(); |
| 6679 | } else { |
| 6680 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6681 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6682 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6683 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6684 | return retVal; |
| 6685 | } else { |
| 6686 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6687 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6688 | + subId + " retVal=false"); |
| 6689 | } |
| 6690 | return false; |
| 6691 | } |
| 6692 | } finally { |
| 6693 | Binder.restoreCallingIdentity(identity); |
| 6694 | } |
| 6695 | } |
| 6696 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6697 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6698 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6699 | if (uid == Process.PHONE_UID) { |
| 6700 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6701 | // TODO (b/184954344): Check for system/phone UID at call site instead of here |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6702 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6703 | } |
| 6704 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6705 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6706 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6707 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6708 | || subController == null) return privilegeFromSim; |
| 6709 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6710 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6711 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6712 | |
| 6713 | final long identity = Binder.clearCallingIdentity(); |
| 6714 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6715 | int subId = phone.getSubId(); |
| 6716 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6717 | // A test override is in place for the privileges for this subId, so don't try to |
| 6718 | // read the subscription privileges. |
| 6719 | return privilegeFromSim; |
| 6720 | } |
| 6721 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6722 | SubscriptionManager subManager = (SubscriptionManager) |
| 6723 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6724 | for (String pkg : packages) { |
| 6725 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6726 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6727 | } |
| 6728 | } |
| 6729 | return privilegeFromSim; |
| 6730 | } finally { |
| 6731 | Binder.restoreCallingIdentity(identity); |
| 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6736 | String pkgName) { |
| 6737 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6738 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6739 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6740 | || subController == null) return privilegeFromSim; |
| 6741 | |
| 6742 | final long identity = Binder.clearCallingIdentity(); |
| 6743 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6744 | int subId = phone.getSubId(); |
| 6745 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6746 | // A test override is in place for the privileges for this subId, so don't try to |
| 6747 | // read the subscription privileges. |
| 6748 | return privilegeFromSim; |
| 6749 | } |
| 6750 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6751 | SubscriptionManager subManager = (SubscriptionManager) |
| 6752 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6753 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6754 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6755 | } finally { |
| 6756 | Binder.restoreCallingIdentity(identity); |
| 6757 | } |
| 6758 | } |
| 6759 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6760 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6761 | public int getCarrierPrivilegeStatus(int subId) { |
| 6762 | final Phone phone = getPhone(subId); |
| 6763 | if (phone == null) { |
| 6764 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6765 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6766 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6767 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6768 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6769 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6770 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6771 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6772 | |
| 6773 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6774 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6775 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6776 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6777 | |
| 6778 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6779 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6780 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6781 | final Phone phone = getPhone(subId); |
| 6782 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6783 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6784 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6785 | } |
| 6786 | UiccProfile profile = |
| 6787 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6788 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6789 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6790 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6791 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6792 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6793 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6794 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6798 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6799 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6800 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6801 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6805 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6806 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6807 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6808 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6809 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6810 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6811 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6812 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | @Override |
| 6816 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6817 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6818 | if (TextUtils.isEmpty(pkgName)) |
| 6819 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6820 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6821 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6822 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6823 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6824 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6825 | continue; |
| 6826 | } |
| 6827 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6828 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6829 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6830 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6831 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6832 | break; |
| 6833 | } |
| 6834 | } |
| 6835 | |
| 6836 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6837 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6838 | |
| 6839 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6840 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6841 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6842 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6843 | loge("phoneId " + phoneId + " is not valid."); |
| 6844 | return null; |
| 6845 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6846 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6847 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6848 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6849 | return null ; |
| 6850 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6851 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6852 | } |
| 6853 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6854 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6855 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6856 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6857 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6858 | List<String> privilegedPackages = new ArrayList<>(); |
| 6859 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6860 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6861 | // has UICC in that slot. |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6862 | if (port != null) { |
| 6863 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6864 | if (packages == null) { |
| 6865 | // Only check packages in user 0 for now |
| 6866 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6867 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6868 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6869 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6870 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6871 | } |
| 6872 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6873 | PackageInfo pkgInfo = packages.get(p); |
| 6874 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 6c442bf | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6875 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6876 | port.getCarrierPrivilegeStatus(pkgInfo), |
Sooraj Sasindran | 6c442bf | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 6877 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6878 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6879 | privilegedPackages.add(pkgInfo.packageName); |
| 6880 | } |
| 6881 | } |
| 6882 | } |
| 6883 | } |
| 6884 | return privilegedPackages; |
| 6885 | } |
| 6886 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6887 | @Override |
| 6888 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6889 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6890 | |
| 6891 | final long identity = Binder.clearCallingIdentity(); |
| 6892 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6893 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6894 | try { |
| 6895 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6896 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6897 | } |
| 6898 | } finally { |
| 6899 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6900 | } |
| 6901 | return privilegedPackages; |
| 6902 | } |
| 6903 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6904 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6905 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6906 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6907 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6908 | return null; |
| 6909 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6910 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6911 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6912 | return null; |
| 6913 | } |
| 6914 | return iccId; |
| 6915 | } |
| 6916 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6917 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6918 | public void setCallComposerStatus(int subId, int status) { |
| 6919 | enforceModifyPermission(); |
| 6920 | |
| 6921 | final long identity = Binder.clearCallingIdentity(); |
| 6922 | try { |
| 6923 | Phone phone = getPhone(subId); |
| 6924 | if (phone != null) { |
| 6925 | Phone defaultPhone = phone.getImsPhone(); |
| 6926 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6927 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6928 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6929 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6930 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6931 | } |
| 6932 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6933 | } catch (ImsException e) { |
| 6934 | throw new ServiceSpecificException(e.getCode()); |
| 6935 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6936 | Binder.restoreCallingIdentity(identity); |
| 6937 | } |
| 6938 | } |
| 6939 | |
| 6940 | @Override |
| 6941 | public int getCallComposerStatus(int subId) { |
| 6942 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6943 | |
| 6944 | final long identity = Binder.clearCallingIdentity(); |
| 6945 | try { |
| 6946 | Phone phone = getPhone(subId); |
| 6947 | if (phone != null) { |
| 6948 | Phone defaultPhone = phone.getImsPhone(); |
| 6949 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6950 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6951 | return imsPhone.getCallComposerStatus(); |
| 6952 | } |
| 6953 | } |
| 6954 | } finally { |
| 6955 | Binder.restoreCallingIdentity(identity); |
| 6956 | } |
| 6957 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6958 | } |
| 6959 | |
| 6960 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6961 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6962 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6963 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6964 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6965 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6966 | final long identity = Binder.clearCallingIdentity(); |
| 6967 | try { |
| 6968 | final String iccId = getIccId(subId); |
| 6969 | final Phone phone = getPhone(subId); |
| 6970 | if (phone == null) { |
| 6971 | return false; |
| 6972 | } |
| 6973 | final String subscriberId = phone.getSubscriberId(); |
| 6974 | |
| 6975 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6976 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6977 | + subscriberId + " to " + number); |
| 6978 | } |
| 6979 | |
| 6980 | if (TextUtils.isEmpty(iccId)) { |
| 6981 | return false; |
| 6982 | } |
| 6983 | |
| 6984 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6985 | |
| 6986 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6987 | if (alphaTag == null) { |
| 6988 | editor.remove(alphaTagPrefKey); |
| 6989 | } else { |
| 6990 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6991 | } |
| 6992 | |
| 6993 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6994 | // track all merged IMSIs based on line number |
| 6995 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6996 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6997 | if (number == null) { |
| 6998 | editor.remove(numberPrefKey); |
| 6999 | editor.remove(subscriberPrefKey); |
| 7000 | } else { |
| 7001 | editor.putString(numberPrefKey, number); |
| 7002 | editor.putString(subscriberPrefKey, subscriberId); |
| 7003 | } |
| 7004 | |
| 7005 | editor.commit(); |
| 7006 | return true; |
| 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7009 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7013 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7014 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7015 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7017 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7018 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7019 | return null; |
| 7020 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7021 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7022 | final long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
| 7024 | String iccId = getIccId(subId); |
| 7025 | if (iccId != null) { |
| 7026 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7027 | if (DBG_MERGE) { |
| 7028 | log("getLine1NumberForDisplay returning " |
| 7029 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7030 | } |
| 7031 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7033 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7034 | return null; |
| 7035 | } finally { |
| 7036 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7037 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7041 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7042 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7043 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7044 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7045 | return null; |
| 7046 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | final long identity = Binder.clearCallingIdentity(); |
| 7049 | try { |
| 7050 | String iccId = getIccId(subId); |
| 7051 | if (iccId != null) { |
| 7052 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7053 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7054 | } |
| 7055 | return null; |
| 7056 | } finally { |
| 7057 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7058 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7059 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7060 | |
| 7061 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7062 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7063 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7064 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7065 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7067 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7068 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7069 | return null; |
| 7070 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7071 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7072 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7073 | // the process, where TelephonyManager was instantiated. |
| 7074 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7075 | final long identity = Binder.clearCallingIdentity(); |
| 7076 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7077 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7078 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7079 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7080 | |
| 7081 | // Figure out what subscribers are currently active |
| 7082 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7083 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7084 | // Only consider subs which match the current subId |
| 7085 | // This logic can be simplified. See b/131189269 for progress. |
| 7086 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7087 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7088 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7089 | |
| 7090 | // First pass, find a number override for an active subscriber |
| 7091 | String mergeNumber = null; |
| 7092 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7093 | for (String key : prefs.keySet()) { |
| 7094 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7095 | final String subscriberId = (String) prefs.get(key); |
| 7096 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7097 | final String iccId = key.substring( |
| 7098 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7099 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7100 | mergeNumber = (String) prefs.get(numberKey); |
| 7101 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7102 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7103 | + " for active subscriber " + subscriberId); |
| 7104 | } |
| 7105 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7106 | break; |
| 7107 | } |
| 7108 | } |
| 7109 | } |
| 7110 | } |
| 7111 | |
| 7112 | // Shortcut when no active merged subscribers |
| 7113 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7114 | return null; |
| 7115 | } |
| 7116 | |
| 7117 | // Second pass, find all subscribers under that line override |
| 7118 | final ArraySet<String> result = new ArraySet<>(); |
| 7119 | for (String key : prefs.keySet()) { |
| 7120 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7121 | final String number = (String) prefs.get(key); |
| 7122 | if (mergeNumber.equals(number)) { |
| 7123 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7124 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7125 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7126 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7127 | result.add(subscriberId); |
| 7128 | } |
| 7129 | } |
| 7130 | } |
| 7131 | } |
| 7132 | |
| 7133 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7134 | Arrays.sort(resultArray); |
| 7135 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7136 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7138 | } |
| 7139 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7142 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7143 | } |
| 7144 | |
| 7145 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7146 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7147 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7148 | |
| 7149 | final long identity = Binder.clearCallingIdentity(); |
| 7150 | try { |
| 7151 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7152 | TelephonyManager.class); |
| 7153 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7154 | if (subscriberId == null) { |
| 7155 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7156 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7157 | + subId); |
| 7158 | } |
| 7159 | return null; |
| 7160 | } |
| 7161 | |
| 7162 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7163 | .getSubscriptionInfo(subId); |
| 7164 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7165 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7166 | if (groupUuid == null) { |
| 7167 | return new String[]{subscriberId}; |
| 7168 | } |
| 7169 | |
| 7170 | // Get all subscriberIds from the group. |
| 7171 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7172 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7173 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7174 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7175 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7176 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7177 | if (subscriberId != null) { |
| 7178 | mergedSubscriberIds.add(subscriberId); |
| 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
| 7185 | |
| 7186 | } |
| 7187 | } |
| 7188 | |
| 7189 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7190 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7191 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7192 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7193 | |
| 7194 | final long identity = Binder.clearCallingIdentity(); |
| 7195 | try { |
| 7196 | final Phone phone = getPhone(subId); |
| 7197 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7198 | } finally { |
| 7199 | Binder.restoreCallingIdentity(identity); |
| 7200 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7201 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7202 | |
| 7203 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7204 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7205 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7206 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7207 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7208 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7209 | |
| 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
| 7212 | final Phone phone = getPhone(subId); |
| 7213 | if (phone == null) { |
| 7214 | return false; |
| 7215 | } |
| 7216 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7217 | cdmaNonRoamingList); |
| 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7220 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7224 | @Deprecated |
| 7225 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7226 | enforceModifyPermission(); |
| 7227 | |
| 7228 | int returnValue = 0; |
| 7229 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7230 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7231 | if(result.exception == null) { |
| 7232 | if (result.result != null) { |
| 7233 | byte[] responseData = (byte[])(result.result); |
| 7234 | if(responseData.length > oemResp.length) { |
| 7235 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7236 | responseData.length + "bytes. Buffer Size is " + |
| 7237 | oemResp.length + "bytes."); |
| 7238 | } |
| 7239 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7240 | returnValue = responseData.length; |
| 7241 | } |
| 7242 | } else { |
| 7243 | CommandException ex = (CommandException) result.exception; |
| 7244 | returnValue = ex.getCommandError().ordinal(); |
| 7245 | if(returnValue > 0) returnValue *= -1; |
| 7246 | } |
| 7247 | } catch (RuntimeException e) { |
| 7248 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7249 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7250 | if(returnValue > 0) returnValue *= -1; |
| 7251 | } |
| 7252 | |
| 7253 | return returnValue; |
| 7254 | } |
| 7255 | |
| 7256 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7257 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7258 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7259 | try { |
| 7260 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7261 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7262 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7263 | } catch (SecurityException e) { |
| 7264 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7265 | throw e; |
| 7266 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7267 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7268 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7269 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7270 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7271 | final long identity = Binder.clearCallingIdentity(); |
| 7272 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7273 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7274 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7275 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7276 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
| 7279 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7280 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7281 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7282 | |
| 7283 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7284 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7285 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7286 | try { |
| 7287 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7288 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7289 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7290 | } |
| 7291 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7292 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7293 | } |
| 7294 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7295 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7296 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7297 | throw new SecurityException("App must be the dialer role holder to" |
| 7298 | + " upload a call composer pic"); |
| 7299 | } |
| 7300 | |
| 7301 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7302 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7303 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7304 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7305 | boolean readUntilEnd = false; |
| 7306 | int totalBytesRead = 0; |
| 7307 | byte[] buffer = new byte[16 * 1024]; |
| 7308 | while (true) { |
| 7309 | int numRead; |
| 7310 | try { |
| 7311 | numRead = input.read(buffer); |
| 7312 | } catch (IOException e) { |
| 7313 | try { |
| 7314 | fd.checkError(); |
| 7315 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7316 | null); |
| 7317 | } catch (IOException e1) { |
| 7318 | // This means that the other side closed explicitly with an error. If this |
| 7319 | // happens, log and ignore. |
| 7320 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7321 | } |
| 7322 | break; |
| 7323 | } |
| 7324 | if (numRead == -1) { |
| 7325 | readUntilEnd = true; |
| 7326 | break; |
| 7327 | } |
| 7328 | totalBytesRead += numRead; |
| 7329 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7330 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7331 | try { |
| 7332 | input.close(); |
| 7333 | } catch (IOException e) { |
| 7334 | // ignore |
| 7335 | } |
| 7336 | break; |
| 7337 | } |
| 7338 | output.write(buffer, 0, numRead); |
| 7339 | } |
| 7340 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7341 | // close is above, where the picture size is too big. |
| 7342 | |
| 7343 | try { |
| 7344 | fd.checkError(); |
| 7345 | } catch (IOException e) { |
| 7346 | loge("Remote end for call composer closed with an error: " + e); |
| 7347 | return; |
| 7348 | } |
| 7349 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7350 | if (!readUntilEnd) { |
| 7351 | loge("Did not finish reading entire image; aborting"); |
| 7352 | return; |
| 7353 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7354 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7355 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7356 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7357 | new CallComposerPictureTransfer.Factory() {}, |
| 7358 | imageData, |
| 7359 | (result) -> { |
| 7360 | if (result.first != null) { |
| 7361 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7362 | Bundle outputResult = new Bundle(); |
| 7363 | outputResult.putParcelable( |
| 7364 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7365 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7366 | outputResult); |
| 7367 | } else { |
| 7368 | callback.send(result.second, null); |
| 7369 | } |
| 7370 | } |
| 7371 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7372 | }); |
| 7373 | } |
| 7374 | |
| 7375 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7376 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7377 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7378 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | |
| 7380 | final long identity = Binder.clearCallingIdentity(); |
| 7381 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7382 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7383 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7384 | } finally { |
| 7385 | Binder.restoreCallingIdentity(identity); |
| 7386 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7390 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7391 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7392 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7393 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7394 | return false; |
| 7395 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7396 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7397 | final long identity = Binder.clearCallingIdentity(); |
| 7398 | try { |
| 7399 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7400 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7401 | // In the long run, we may instead need to check if there exists a connection service |
| 7402 | // which can support video calling. |
| 7403 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7404 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | return imsManager.isVtEnabledByPlatform() |
| 7406 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7407 | && imsManager.isVtEnabledByUser(); |
| 7408 | } finally { |
| 7409 | Binder.restoreCallingIdentity(identity); |
| 7410 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7411 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7412 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7413 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7414 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7415 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7417 | mApp, subId, callingPackage, callingFeatureId, |
| 7418 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7419 | return false; |
| 7420 | } |
| 7421 | |
| 7422 | final long identity = Binder.clearCallingIdentity(); |
| 7423 | try { |
| 7424 | CarrierConfigManager configManager = |
| 7425 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7426 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7427 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7428 | } finally { |
| 7429 | Binder.restoreCallingIdentity(identity); |
| 7430 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7431 | } |
| 7432 | |
| 7433 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7434 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7435 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7436 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | return false; |
| 7438 | } |
| 7439 | |
| 7440 | final long identity = Binder.clearCallingIdentity(); |
| 7441 | try { |
| 7442 | CarrierConfigManager configManager = |
| 7443 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7444 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7446 | } finally { |
| 7447 | Binder.restoreCallingIdentity(identity); |
| 7448 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7449 | } |
| 7450 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7451 | @Override |
| 7452 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7453 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7454 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7455 | } |
| 7456 | |
| 7457 | @Override |
| 7458 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7459 | final long identity = Binder.clearCallingIdentity(); |
| 7460 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7461 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7462 | } finally { |
| 7463 | Binder.restoreCallingIdentity(identity); |
| 7464 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7465 | } |
| 7466 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7467 | /** |
| 7468 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7469 | * support for the feature and device firmware support. |
| 7470 | * |
| 7471 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7472 | */ |
| 7473 | @Override |
| 7474 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7475 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7476 | final Phone phone = getPhone(subscriptionId); |
| 7477 | if (phone == null) { |
| 7478 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7479 | return false; |
| 7480 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7482 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7484 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7485 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | return isCarrierSupported && isDeviceSupported; |
| 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7490 | } |
| 7491 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7492 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7493 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7494 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7495 | * Otherwise. only returns true if the device and carrier both also support RTT. |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7496 | */ |
| 7497 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7498 | final long identity = Binder.clearCallingIdentity(); |
| 7499 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7500 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7501 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7502 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7503 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7504 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7505 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | } finally { |
| 7507 | Binder.restoreCallingIdentity(identity); |
| 7508 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7509 | } |
| 7510 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7511 | @Deprecated |
| 7512 | @Override |
| 7513 | public String getDeviceId(String callingPackage) { |
| 7514 | return getDeviceIdWithFeature(callingPackage, null); |
| 7515 | } |
| 7516 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7517 | /** |
| 7518 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7519 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7520 | * |
| 7521 | * <p>Requires Permission: |
| 7522 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7523 | */ |
| 7524 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7525 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7526 | try { |
| 7527 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7528 | } catch (SecurityException se) { |
| 7529 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7530 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7531 | + Binder.getCallingUid()); |
| 7532 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7533 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7534 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7535 | return null; |
| 7536 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7537 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7538 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7539 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7540 | return null; |
| 7541 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | |
| 7543 | final long identity = Binder.clearCallingIdentity(); |
| 7544 | try { |
| 7545 | return phone.getDeviceId(); |
| 7546 | } finally { |
| 7547 | Binder.restoreCallingIdentity(identity); |
| 7548 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7549 | } |
| 7550 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7551 | /** |
| 7552 | * {@hide} |
| 7553 | * Returns the IMS Registration Status on a particular subid |
| 7554 | * |
| 7555 | * @param subId |
| 7556 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7557 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7558 | Phone phone = getPhone(subId); |
| 7559 | if (phone != null) { |
| 7560 | return phone.isImsRegistered(); |
| 7561 | } else { |
| 7562 | return false; |
| 7563 | } |
| 7564 | } |
| 7565 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7566 | @Override |
| 7567 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7568 | final long identity = Binder.clearCallingIdentity(); |
| 7569 | try { |
| 7570 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7571 | } finally { |
| 7572 | Binder.restoreCallingIdentity(identity); |
| 7573 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7574 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7575 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7576 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7577 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7578 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7579 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7580 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7581 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7582 | } |
| 7583 | final long identity = Binder.clearCallingIdentity(); |
| 7584 | try { |
| 7585 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7586 | } finally { |
| 7587 | Binder.restoreCallingIdentity(identity); |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7592 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7593 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7594 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7595 | mApp, |
| 7596 | subscriptionId, |
| 7597 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7598 | final long identity = Binder.clearCallingIdentity(); |
| 7599 | try { |
| 7600 | Phone phone = getPhone(subscriptionId); |
| 7601 | if (phone == null) { |
| 7602 | return null; |
| 7603 | } |
| 7604 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7605 | } finally { |
| 7606 | Binder.restoreCallingIdentity(identity); |
| 7607 | } |
| 7608 | } |
| 7609 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7610 | /** |
| 7611 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7612 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7613 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7614 | final long identity = Binder.clearCallingIdentity(); |
| 7615 | try { |
| 7616 | Phone phone = getPhone(subId); |
| 7617 | if (phone != null) { |
| 7618 | return phone.isWifiCallingEnabled(); |
| 7619 | } else { |
| 7620 | return false; |
| 7621 | } |
| 7622 | } finally { |
| 7623 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7624 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7625 | } |
| 7626 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7627 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7628 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7629 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7630 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7631 | final long identity = Binder.clearCallingIdentity(); |
| 7632 | try { |
| 7633 | Phone phone = getPhone(subId); |
| 7634 | if (phone != null) { |
| 7635 | return phone.isVideoEnabled(); |
| 7636 | } else { |
| 7637 | return false; |
| 7638 | } |
| 7639 | } finally { |
| 7640 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7641 | } |
| 7642 | } |
| 7643 | |
| 7644 | /** |
| 7645 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7646 | * defined in {@link ImsRegistrationImplBase}. |
| 7647 | */ |
| 7648 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | final long identity = Binder.clearCallingIdentity(); |
| 7650 | try { |
| 7651 | Phone phone = getPhone(subId); |
| 7652 | if (phone != null) { |
| 7653 | return phone.getImsRegistrationTech(); |
| 7654 | } else { |
| 7655 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7656 | } |
| 7657 | } finally { |
| 7658 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7659 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7662 | @Override |
| 7663 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7664 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7665 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7666 | return; |
| 7667 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7668 | Phone defaultPhone = getDefaultPhone(); |
| 7669 | if (defaultPhone != null) { |
| 7670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7671 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7672 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7673 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7674 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7675 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7676 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7677 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7678 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7679 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7680 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7681 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7682 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7683 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7684 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7685 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7686 | // There has been issues when Sms raw table somehow stores orphan |
| 7687 | // fragments. They lead to garbled message when new fragments come |
| 7688 | // in and combined with those stale ones. In case this happens again, |
| 7689 | // user can reset all network settings which will clean up this table. |
| 7690 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7691 | // Clean up IMS settings as well here. |
| 7692 | int slotId = getSlotIndex(subId); |
| 7693 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7694 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7695 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7696 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7697 | if (defaultPhone == null) { |
| 7698 | return; |
| 7699 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7700 | // Erase modem config if erase modem on network setting is enabled. |
| 7701 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7702 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7703 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7704 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7705 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7706 | |
| 7707 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7708 | } finally { |
| 7709 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7710 | } |
| 7711 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7712 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7713 | @VisibleForTesting |
| 7714 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7715 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7716 | return; |
| 7717 | } |
| 7718 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7719 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7720 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7721 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7722 | "user=" + defaultNetworkType); |
| 7723 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7724 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7725 | defaultNetworkType, null); |
| 7726 | } |
| 7727 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7728 | private void cleanUpSmsRawTable(Context context) { |
| 7729 | ContentResolver resolver = context.getContentResolver(); |
| 7730 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7731 | resolver.delete(uri, null, null); |
| 7732 | } |
| 7733 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7734 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7735 | public String getSimLocaleForSubscriber(int subId) { |
| 7736 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7737 | final Phone phone = getPhone(subId); |
| 7738 | if (phone == null) { |
| 7739 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7740 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7741 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | final long identity = Binder.clearCallingIdentity(); |
| 7743 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7744 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7745 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7746 | if (info == null) { |
| 7747 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7748 | return null; |
| 7749 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7750 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7751 | // preferences (EF-PL and EF-LI)... |
| 7752 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7753 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7754 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7755 | if (localeFromDefaultSim != null) { |
| 7756 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7757 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7758 | + localeFromDefaultSim); |
| 7759 | return localeFromDefaultSim.toLanguageTag(); |
| 7760 | } else { |
| 7761 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7762 | } |
| 7763 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7765 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7766 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7767 | // the SIM and carrier preferences does not include a country we add the country |
| 7768 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7769 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7770 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7771 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | return mccLocale.toLanguageTag(); |
| 7773 | } |
| 7774 | |
| 7775 | if (DBG) log("No locale found - returning null"); |
| 7776 | return null; |
| 7777 | } finally { |
| 7778 | Binder.restoreCallingIdentity(identity); |
| 7779 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7783 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7784 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7785 | } |
| 7786 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7787 | /** |
| 7788 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7789 | */ |
| 7790 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7791 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7792 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7793 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7794 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7795 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7796 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7797 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7798 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7799 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7800 | * representing the state of the modem. |
| 7801 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7802 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7803 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7804 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7805 | */ |
| 7806 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7807 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7808 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7809 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7810 | |
| 7811 | final long identity = Binder.clearCallingIdentity(); |
| 7812 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7813 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | } finally { |
| 7815 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7816 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7817 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7818 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7819 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7820 | // less than total activity duration. |
| 7821 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7822 | if (info == null) { |
| 7823 | return false; |
| 7824 | } |
| 7825 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7826 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7827 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7828 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7829 | return (info.isValid() |
| 7830 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7831 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7832 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7833 | && (totalTxTimeMs <= activityDurationMs)); |
| 7834 | } |
| 7835 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7836 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7837 | * Returns the service state information on specified subscription. |
| 7838 | */ |
| 7839 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7840 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7841 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7842 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7843 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7844 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7845 | return null; |
| 7846 | } |
| 7847 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7848 | boolean hasFinePermission = false; |
| 7849 | boolean hasCoarsePermission = false; |
| 7850 | if (!renounceFineLocationAccess) { |
| 7851 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7852 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7853 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7854 | .setCallingPackage(callingPackage) |
| 7855 | .setCallingFeatureId(callingFeatureId) |
| 7856 | .setCallingPid(Binder.getCallingPid()) |
| 7857 | .setCallingUid(Binder.getCallingUid()) |
| 7858 | .setMethod("getServiceStateForSubscriber") |
| 7859 | .setLogAsInfo(true) |
| 7860 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7861 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7862 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7863 | .build()); |
| 7864 | hasFinePermission = |
| 7865 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7866 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7867 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7868 | if (!renounceCoarseLocationAccess) { |
| 7869 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7870 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7871 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7872 | .setCallingPackage(callingPackage) |
| 7873 | .setCallingFeatureId(callingFeatureId) |
| 7874 | .setCallingPid(Binder.getCallingPid()) |
| 7875 | .setCallingUid(Binder.getCallingUid()) |
| 7876 | .setMethod("getServiceStateForSubscriber") |
| 7877 | .setLogAsInfo(true) |
| 7878 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7879 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7880 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7881 | .build()); |
| 7882 | hasCoarsePermission = |
| 7883 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7884 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7885 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7886 | final Phone phone = getPhone(subId); |
| 7887 | if (phone == null) { |
| 7888 | return null; |
| 7889 | } |
| 7890 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7891 | final long identity = Binder.clearCallingIdentity(); |
| 7892 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7893 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7894 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7895 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7896 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7897 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7898 | Rlog.d(LOG_TAG, |
| 7899 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7900 | return null; |
| 7901 | } |
| 7902 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7903 | ServiceState ss = phone.getServiceState(); |
| 7904 | |
| 7905 | // Scrub out the location info in ServiceState depending on what level of access |
| 7906 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7907 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7908 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7909 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | } finally { |
| 7911 | Binder.restoreCallingIdentity(identity); |
| 7912 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7913 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7914 | |
| 7915 | /** |
| 7916 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7917 | * |
| 7918 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7919 | * voicemail ringtone. |
| 7920 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7921 | * PhoneAccount. |
| 7922 | */ |
| 7923 | @Override |
| 7924 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7925 | final long identity = Binder.clearCallingIdentity(); |
| 7926 | try { |
| 7927 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7928 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7929 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7930 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7931 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7932 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7933 | } finally { |
| 7934 | Binder.restoreCallingIdentity(identity); |
| 7935 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7936 | } |
| 7937 | |
| 7938 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7939 | * Sets the per-account voicemail ringtone. |
| 7940 | * |
| 7941 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7942 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7943 | * |
| 7944 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7945 | * voicemail ringtone. |
| 7946 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7947 | * PhoneAccount. |
| 7948 | */ |
| 7949 | @Override |
| 7950 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7951 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7952 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7953 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7954 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7955 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7956 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7957 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7958 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7960 | |
| 7961 | final long identity = Binder.clearCallingIdentity(); |
| 7962 | try { |
| 7963 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7964 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7965 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7966 | } |
| 7967 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7968 | } finally { |
| 7969 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7970 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7971 | } |
| 7972 | |
| 7973 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7974 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7975 | * |
| 7976 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7977 | * voicemail vibration setting. |
| 7978 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7979 | */ |
| 7980 | @Override |
| 7981 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7982 | final long identity = Binder.clearCallingIdentity(); |
| 7983 | try { |
| 7984 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7985 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7986 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7987 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7988 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7989 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7990 | } finally { |
| 7991 | Binder.restoreCallingIdentity(identity); |
| 7992 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7993 | } |
| 7994 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7995 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7996 | * Sets the per-account voicemail vibration. |
| 7997 | * |
| 7998 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7999 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8000 | * |
| 8001 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8002 | * voicemail vibration setting. |
| 8003 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8004 | * specific PhoneAccount. |
| 8005 | */ |
| 8006 | @Override |
| 8007 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8008 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8009 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8010 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8011 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8012 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8013 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8014 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8015 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8016 | } |
| 8017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | final long identity = Binder.clearCallingIdentity(); |
| 8019 | try { |
| 8020 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8021 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8022 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8023 | } |
| 8024 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8025 | } finally { |
| 8026 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8027 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8028 | } |
| 8029 | |
| 8030 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8031 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8032 | * |
| 8033 | * @throws SecurityException if the caller does not have the required permission |
| 8034 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8035 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8036 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8037 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8038 | } |
| 8039 | |
| 8040 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8041 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8042 | * permission. |
| 8043 | * |
| 8044 | * @throws SecurityException if the caller does not have the required permission |
| 8045 | */ |
| 8046 | private void enforceSendSmsPermission() { |
| 8047 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8048 | } |
| 8049 | |
| 8050 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8051 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8052 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8053 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8054 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8055 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8056 | final long identity = Binder.clearCallingIdentity(); |
| 8057 | try { |
| 8058 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8059 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8060 | if (componentName == null) { |
| 8061 | throw new SecurityException( |
| 8062 | "Caller not current active visual voicemail package[null]"); |
| 8063 | } |
| 8064 | String vvmPackage = componentName.getPackageName(); |
| 8065 | if (!callingPackage.equals(vvmPackage)) { |
| 8066 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8067 | + vvmPackage + "]"); |
| 8068 | } |
| 8069 | } finally { |
| 8070 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8071 | } |
| 8072 | } |
| 8073 | |
| 8074 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8075 | * Return the application ID for the app type. |
| 8076 | * |
| 8077 | * @param subId the subscription ID that this request applies to. |
| 8078 | * @param appType the uicc app type. |
| 8079 | * @return Application ID for specificied app type, or null if no uicc. |
| 8080 | */ |
| 8081 | @Override |
| 8082 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8083 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8084 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8085 | |
| 8086 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8087 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8088 | if (phone == null) { |
| 8089 | return null; |
| 8090 | } |
| 8091 | String aid = null; |
| 8092 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8093 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8094 | .getApplicationByType(appType).getAid(); |
| 8095 | } catch (Exception e) { |
| 8096 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8097 | } |
| 8098 | return aid; |
| 8099 | } finally { |
| 8100 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8101 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8102 | } |
| 8103 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8104 | /** |
| 8105 | * Return the Electronic Serial Number. |
| 8106 | * |
| 8107 | * @param subId the subscription ID that this request applies to. |
| 8108 | * @return ESN or null if error. |
| 8109 | */ |
| 8110 | @Override |
| 8111 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8112 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8113 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | |
| 8115 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8116 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8117 | if (phone == null) { |
| 8118 | return null; |
| 8119 | } |
| 8120 | String esn = null; |
| 8121 | try { |
| 8122 | esn = phone.getEsn(); |
| 8123 | } catch (Exception e) { |
| 8124 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8125 | } |
| 8126 | return esn; |
| 8127 | } finally { |
| 8128 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8129 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8132 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8133 | * Return the Preferred Roaming List Version. |
| 8134 | * |
| 8135 | * @param subId the subscription ID that this request applies to. |
| 8136 | * @return PRLVersion or null if error. |
| 8137 | */ |
| 8138 | @Override |
| 8139 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8140 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8141 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8142 | |
| 8143 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8144 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8145 | if (phone == null) { |
| 8146 | return null; |
| 8147 | } |
| 8148 | String cdmaPrlVersion = null; |
| 8149 | try { |
| 8150 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8151 | } catch (Exception e) { |
| 8152 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8153 | } |
| 8154 | return cdmaPrlVersion; |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8157 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8158 | } |
| 8159 | |
| 8160 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8161 | * Get snapshot of Telephony histograms |
| 8162 | * @return List of Telephony histograms |
| 8163 | * @hide |
| 8164 | */ |
| 8165 | @Override |
| 8166 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8168 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8169 | |
| 8170 | final long identity = Binder.clearCallingIdentity(); |
| 8171 | try { |
| 8172 | return RIL.getTelephonyRILTimingHistograms(); |
| 8173 | } finally { |
| 8174 | Binder.restoreCallingIdentity(identity); |
| 8175 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8176 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8177 | |
| 8178 | /** |
| 8179 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8180 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8181 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8182 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8183 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8184 | * @return Integer with the result of the operation, as defined in {@link TelephonyManager}. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8185 | */ |
| 8186 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8187 | @TelephonyManager.SetCarrierRestrictionResult |
| 8188 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8189 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8190 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8191 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8192 | if (carrierRestrictionRules == null) { |
| 8193 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8194 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8198 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8199 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8203 | } |
| 8204 | |
| 8205 | /** |
| 8206 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8207 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8208 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8209 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8210 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8211 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8212 | */ |
| 8213 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8214 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8215 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8216 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8217 | |
| 8218 | final long identity = Binder.clearCallingIdentity(); |
| 8219 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8220 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8221 | if (response instanceof CarrierRestrictionRules) { |
| 8222 | return (CarrierRestrictionRules) response; |
| 8223 | } |
| 8224 | // Response is an Exception of some kind, |
| 8225 | // which is signalled to the user as a NULL retval |
| 8226 | return null; |
| 8227 | } catch (Exception e) { |
| 8228 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8229 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8230 | } finally { |
| 8231 | Binder.restoreCallingIdentity(identity); |
| 8232 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8233 | } |
| 8234 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8235 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8236 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8237 | * @param subId the subscription ID that this action applies to. |
| 8238 | * @param enabled control enable or disable radio. |
| 8239 | * {@hide} |
| 8240 | */ |
| 8241 | @Override |
| 8242 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8243 | enforceModifyPermission(); |
| 8244 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8245 | |
| 8246 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8247 | if (phone == null) { |
| 8248 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8249 | return; |
| 8250 | } |
| 8251 | try { |
| 8252 | phone.carrierActionSetRadioEnabled(enabled); |
| 8253 | } catch (Exception e) { |
| 8254 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8255 | } finally { |
| 8256 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8257 | } |
| 8258 | } |
| 8259 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8260 | /** |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8261 | * Enable or disable Voice over NR (VoNR) |
| 8262 | * @param subId the subscription ID that this action applies to. |
| 8263 | * @param enabled enable or disable VoNR. |
| 8264 | * @return operation result. |
| 8265 | */ |
| 8266 | @Override |
| 8267 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8268 | enforceModifyPermission(); |
| 8269 | final Phone phone = getPhone(subId); |
| 8270 | |
| 8271 | final long identity = Binder.clearCallingIdentity(); |
| 8272 | if (phone == null) { |
| 8273 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8274 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8275 | } |
| 8276 | |
| 8277 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8278 | try { |
| 8279 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8280 | workSource); |
| 8281 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8282 | |
| 8283 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8284 | if (DBG) { |
| 8285 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8286 | } |
| 8287 | SubscriptionManager.setSubscriptionProperty( |
| 8288 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8289 | (enabled ? "1" : "0")); |
| 8290 | } |
| 8291 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8292 | return result; |
| 8293 | } finally { |
| 8294 | Binder.restoreCallingIdentity(identity); |
| 8295 | } |
| 8296 | } |
| 8297 | |
| 8298 | /** |
| 8299 | * Is voice over NR enabled |
| 8300 | * @return true if VoNR is enabled else false |
| 8301 | */ |
| 8302 | @Override |
| 8303 | public boolean isVoNrEnabled(int subId) { |
| 8304 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8305 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8306 | final long identity = Binder.clearCallingIdentity(); |
| 8307 | try { |
| 8308 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8309 | null, subId, workSource); |
| 8310 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8311 | return isEnabled; |
| 8312 | } finally { |
| 8313 | Binder.restoreCallingIdentity(identity); |
| 8314 | } |
| 8315 | } |
| 8316 | |
| 8317 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8318 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8319 | * network status based on which carrier apps could apply actions accordingly, |
| 8320 | * enable/disable default url handler for example. |
| 8321 | * |
| 8322 | * @param subId the subscription ID that this action applies to. |
| 8323 | * @param report control start/stop reporting the default network status. |
| 8324 | * {@hide} |
| 8325 | */ |
| 8326 | @Override |
| 8327 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8328 | enforceModifyPermission(); |
| 8329 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | |
| 8331 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8332 | if (phone == null) { |
| 8333 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8334 | return; |
| 8335 | } |
| 8336 | try { |
| 8337 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8338 | } catch (Exception e) { |
| 8339 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8342 | } |
| 8343 | } |
| 8344 | |
| 8345 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8346 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8347 | * @param subId the subscription ID that this action applies to. |
| 8348 | * {@hide} |
| 8349 | */ |
| 8350 | @Override |
| 8351 | public void carrierActionResetAll(int subId) { |
| 8352 | enforceModifyPermission(); |
| 8353 | final Phone phone = getPhone(subId); |
| 8354 | if (phone == null) { |
| 8355 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8356 | return; |
| 8357 | } |
| 8358 | try { |
| 8359 | phone.carrierActionResetAll(); |
| 8360 | } catch (Exception e) { |
| 8361 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8362 | } |
| 8363 | } |
| 8364 | |
| 8365 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8366 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8367 | * bug report is being generated. |
| 8368 | */ |
| 8369 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8370 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8371 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8372 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8373 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8374 | + Binder.getCallingPid() |
| 8375 | + ", uid=" + Binder.getCallingUid() |
| 8376 | + "without permission " |
| 8377 | + android.Manifest.permission.DUMP); |
| 8378 | return; |
| 8379 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8380 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8381 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8382 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8383 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8384 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8385 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8386 | @NonNull String[] args) { |
| 8387 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8388 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8389 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8390 | } |
| 8391 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8392 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8393 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8394 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8395 | * @param reason the reason the data enable change is taking place |
| 8396 | * @param enabled True if enabling the data, otherwise disabling. |
| 8397 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8398 | */ |
| 8399 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8400 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8401 | boolean enabled) { |
| 8402 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8403 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8404 | try { |
| 8405 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8406 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8407 | } catch (SecurityException se) { |
| 8408 | enforceModifyPermission(); |
| 8409 | } |
| 8410 | } else { |
| 8411 | enforceModifyPermission(); |
| 8412 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8413 | |
| 8414 | final long identity = Binder.clearCallingIdentity(); |
| 8415 | try { |
| 8416 | Phone phone = getPhone(subId); |
| 8417 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8418 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8419 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8420 | } else { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8421 | if (phone.isUsingNewDataStack()) { |
| 8422 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8423 | } else { |
| 8424 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8425 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8426 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8427 | } |
| 8428 | } finally { |
| 8429 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8430 | } |
| 8431 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8432 | |
| 8433 | /** |
| 8434 | * Get Client request stats |
| 8435 | * @return List of Client Request Stats |
| 8436 | * @hide |
| 8437 | */ |
| 8438 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8439 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8440 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8441 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8442 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8443 | return null; |
| 8444 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8445 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8446 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | final long identity = Binder.clearCallingIdentity(); |
| 8448 | try { |
| 8449 | if (phone != null) { |
| 8450 | return phone.getClientRequestStats(); |
| 8451 | } |
| 8452 | |
| 8453 | return null; |
| 8454 | } finally { |
| 8455 | Binder.restoreCallingIdentity(identity); |
| 8456 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8457 | } |
| 8458 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8459 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8460 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8461 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8462 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8463 | |
| 8464 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8465 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8466 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8467 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8468 | * @param state State of SIM (power down, power up, pass through) |
| 8469 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8470 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8471 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8472 | * |
| 8473 | **/ |
| 8474 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8475 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8476 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8477 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8478 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8479 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8480 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8481 | final long identity = Binder.clearCallingIdentity(); |
| 8482 | try { |
| 8483 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8484 | phone.setSimPowerState(state, null, workSource); |
| 8485 | } |
| 8486 | } finally { |
| 8487 | Binder.restoreCallingIdentity(identity); |
| 8488 | } |
| 8489 | } |
| 8490 | |
| 8491 | /** |
| 8492 | * Set SIM card power state. |
| 8493 | * |
| 8494 | * @param slotIndex SIM slot id. |
| 8495 | * @param state State of SIM (power down, power up, pass through) |
| 8496 | * @param callback callback to trigger after success or failure |
| 8497 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8498 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8499 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8500 | * |
| 8501 | **/ |
| 8502 | @Override |
| 8503 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8504 | IIntegerConsumer callback) { |
| 8505 | enforceModifyPermission(); |
| 8506 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8507 | |
| 8508 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8509 | |
| 8510 | final long identity = Binder.clearCallingIdentity(); |
| 8511 | try { |
| 8512 | if (phone != null) { |
| 8513 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8514 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8515 | } |
| 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8518 | } |
| 8519 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8520 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8521 | private boolean isUssdApiAllowed(int subId) { |
| 8522 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8523 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8524 | if (configManager == null) { |
| 8525 | return false; |
| 8526 | } |
| 8527 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8528 | if (pb == null) { |
| 8529 | return false; |
| 8530 | } |
| 8531 | return pb.getBoolean( |
| 8532 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8533 | } |
| 8534 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8535 | /** |
| 8536 | * Check if phone is in emergency callback mode |
| 8537 | * @return true if phone is in emergency callback mode |
| 8538 | * @param subId sub id |
| 8539 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8540 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8541 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8542 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8543 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8544 | |
| 8545 | final long identity = Binder.clearCallingIdentity(); |
| 8546 | try { |
| 8547 | if (phone != null) { |
| 8548 | return phone.isInEcm(); |
| 8549 | } else { |
| 8550 | return false; |
| 8551 | } |
| 8552 | } finally { |
| 8553 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8554 | } |
| 8555 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8556 | |
| 8557 | /** |
| 8558 | * Get the current signal strength information for the given subscription. |
| 8559 | * Because this information is not updated when the device is in a low power state |
| 8560 | * it should not be relied-upon to be current. |
| 8561 | * @param subId Subscription index |
| 8562 | * @return the most recent cached signal strength info from the modem |
| 8563 | */ |
| 8564 | @Override |
| 8565 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | Phone p = getPhone(subId); |
| 8569 | if (p == null) { |
| 8570 | return null; |
| 8571 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8573 | return p.getSignalStrength(); |
| 8574 | } finally { |
| 8575 | Binder.restoreCallingIdentity(identity); |
| 8576 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8577 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8578 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8579 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8580 | * Get the current modem radio state for the given slot. |
| 8581 | * @param slotIndex slot index. |
| 8582 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8583 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8584 | * @return the current radio power state from the modem |
| 8585 | */ |
| 8586 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8587 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8588 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8589 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8590 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8591 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8592 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8593 | } |
| 8594 | |
| 8595 | final long identity = Binder.clearCallingIdentity(); |
| 8596 | try { |
| 8597 | return phone.getRadioPowerState(); |
| 8598 | } finally { |
| 8599 | Binder.restoreCallingIdentity(identity); |
| 8600 | } |
| 8601 | } |
| 8602 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8603 | } |
| 8604 | |
| 8605 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8606 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8607 | * |
| 8608 | * <p>Requires one of the following permissions: |
| 8609 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8610 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8611 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8612 | * privileges. |
| 8613 | * |
| 8614 | * @param subId subscription id |
| 8615 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8616 | * {@code false}. |
| 8617 | */ |
| 8618 | @Override |
| 8619 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8620 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8621 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8622 | try { |
| 8623 | mApp.enforceCallingOrSelfPermission( |
| 8624 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8625 | functionName); |
| 8626 | } catch (Exception e) { |
| 8627 | mApp.enforceCallingOrSelfPermission( |
| 8628 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8629 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8630 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8631 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8632 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8633 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8634 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8635 | boolean isEnabled = false; |
| 8636 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8637 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8638 | Phone phone = getPhone(subId); |
| 8639 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8642 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8643 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8644 | } |
| 8645 | |
| 8646 | |
| 8647 | /** |
| 8648 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8649 | * |
| 8650 | * <p> Requires permission: |
| 8651 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8652 | * privileges. |
| 8653 | * |
| 8654 | * @param subId subscription id |
| 8655 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8656 | */ |
| 8657 | @Override |
| 8658 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8660 | mApp, subId, "setDataRoamingEnabled"); |
| 8661 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8662 | final long identity = Binder.clearCallingIdentity(); |
| 8663 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8664 | Phone phone = getPhone(subId); |
| 8665 | if (phone != null) { |
| 8666 | phone.setDataRoamingEnabled(isEnabled); |
| 8667 | } |
| 8668 | } finally { |
| 8669 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8670 | } |
| 8671 | } |
| 8672 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8673 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8674 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8675 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8676 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8677 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8678 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8679 | boolean isAllowed = true; |
| 8680 | final long identity = Binder.clearCallingIdentity(); |
| 8681 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8682 | Phone phone = getPhone(subId); |
| 8683 | if (phone != null) { |
| 8684 | isAllowed = phone.isCspPlmnEnabled(); |
| 8685 | } |
| 8686 | } finally { |
| 8687 | Binder.restoreCallingIdentity(identity); |
| 8688 | } |
| 8689 | return isAllowed; |
| 8690 | } |
| 8691 | |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8692 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8693 | UiccProfile profile = port.getUiccProfile(); |
| 8694 | if (profile == null || |
| 8695 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8696 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8697 | return false; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8698 | } |
| 8699 | return true; |
| 8700 | } |
| 8701 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8702 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8703 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8704 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8705 | mApp.getSystemService(AppOpsManager.class) |
| 8706 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8707 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8708 | boolean hasReadPermission = false; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8709 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8710 | try { |
| 8711 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8712 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8713 | } catch (SecurityException e) { |
| 8714 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8715 | // has carrier privileges on an active UICC |
| 8716 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8717 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8718 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8719 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8720 | } |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8721 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8722 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8723 | Binder.getCallingUid())) { |
| 8724 | isIccIdAccessRestricted = true; |
| 8725 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8726 | final long identity = Binder.clearCallingIdentity(); |
| 8727 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8728 | UiccController uiccController = UiccController.getInstance(); |
| 8729 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8730 | if (hasReadPermission) { |
| 8731 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8732 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8733 | |
| 8734 | // Remove private info if the caller doesn't have access |
| 8735 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8736 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8737 | //setting the value after compatibility check |
| 8738 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8739 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8740 | // is available |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8741 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8742 | if (card == null) { |
| 8743 | // assume no access if the card is unavailable |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8744 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8745 | continue; |
| 8746 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8747 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8748 | if (portInfos.isEmpty()) { |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8749 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8750 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8751 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8752 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8753 | for (UiccPortInfo portInfo : portInfos) { |
| 8754 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8755 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8756 | if (port == null) { |
| 8757 | // assume no access if port is null |
| 8758 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8759 | continue; |
| 8760 | } |
| 8761 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8762 | uiccPortInfos.add(portInfo); |
| 8763 | } else { |
| 8764 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8765 | } |
| 8766 | } |
| 8767 | filteredInfos.add(new UiccCardInfo( |
| 8768 | cardInfo.isEuicc(), |
| 8769 | cardInfo.getCardId(), |
| 8770 | null, |
| 8771 | cardInfo.getPhysicalSlotIndex(), |
| 8772 | cardInfo.isRemovable(), |
| 8773 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8774 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8775 | } |
| 8776 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8777 | } finally { |
| 8778 | Binder.restoreCallingIdentity(identity); |
| 8779 | } |
| 8780 | } |
| 8781 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8782 | /** |
| 8783 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8784 | * generally private and require carrier privileges to view. |
| 8785 | * |
| 8786 | * @hide |
| 8787 | */ |
| 8788 | @NonNull |
| 8789 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8790 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8791 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8792 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8793 | } |
| 8794 | return new UiccCardInfo( |
| 8795 | cardInfo.isEuicc(), |
| 8796 | cardInfo.getCardId(), |
| 8797 | null, |
| 8798 | cardInfo.getPhysicalSlotIndex(), |
| 8799 | cardInfo.isRemovable(), |
| 8800 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8801 | portinfo |
| 8802 | ); |
| 8803 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8804 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8805 | /** |
| 8806 | * @hide |
| 8807 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8808 | * These values are generally private and require carrier privileges to view. |
| 8809 | */ |
| 8810 | @NonNull |
| 8811 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8812 | return new UiccPortInfo( |
| 8813 | UiccPortInfo.ICCID_REDACTED, |
| 8814 | portInfo.getPortIndex(), |
| 8815 | portInfo.getLogicalSlotIndex(), |
| 8816 | portInfo.isActive() |
| 8817 | ); |
| 8818 | } |
| 8819 | @Override |
| 8820 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8821 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8822 | mApp.getSystemService(AppOpsManager.class) |
| 8823 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8824 | |
| 8825 | boolean hasReadPermission = false; |
| 8826 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8827 | |
| 8828 | try { |
| 8829 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8830 | hasReadPermission = true; |
| 8831 | } catch (SecurityException e) { |
| 8832 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8833 | // has carrier privileges on an active UICC |
| 8834 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8835 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8836 | hasReadPermission = true; |
| 8837 | } |
| 8838 | } |
| 8839 | |
| 8840 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8841 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8842 | Binder.getCallingUid())) { |
| 8843 | isLogicalSlotAccessRestricted = true; |
| 8844 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8845 | final long identity = Binder.clearCallingIdentity(); |
| 8846 | try { |
| 8847 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8848 | if (slots == null) { |
| 8849 | Rlog.i(LOG_TAG, "slots is null."); |
| 8850 | return null; |
| 8851 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8852 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8853 | for (int i = 0; i < slots.length; i++) { |
| 8854 | UiccSlot slot = slots[i]; |
| 8855 | if (slot == null) { |
| 8856 | continue; |
| 8857 | } |
| 8858 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8859 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8860 | UiccCard card = slot.getUiccCard(); |
| 8861 | if (card != null) { |
| 8862 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8863 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8864 | cardId = slot.getEid(); |
| 8865 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8866 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 8867 | // read permission otherwise set to null.(card is null which means no |
| 8868 | // carrier permission) |
| 8869 | cardId = hasReadPermission ? slot.getIccId( |
| 8870 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8871 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8872 | } |
| 8873 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8874 | if (cardId != null) { |
| 8875 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8876 | // if cardId is an EID, it's all digits so this is fine |
| 8877 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8878 | } |
| 8879 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8880 | int cardState = 0; |
| 8881 | switch (slot.getCardState()) { |
| 8882 | case CARDSTATE_ABSENT: |
| 8883 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8884 | break; |
| 8885 | case CARDSTATE_PRESENT: |
| 8886 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8887 | break; |
| 8888 | case CARDSTATE_ERROR: |
| 8889 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8890 | break; |
| 8891 | case CARDSTATE_RESTRICTED: |
| 8892 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8893 | break; |
| 8894 | default: |
| 8895 | break; |
| 8896 | |
| 8897 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8898 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8899 | int[] portIndexes = slot.getPortList(); |
| 8900 | for (int portIdx : portIndexes) { |
| 8901 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 8902 | callingPackage, hasReadPermission)); |
| 8903 | if (slot.isPortActive(portIdx)) { |
| 8904 | UiccPort port = slot.getUiccCard().getUiccPort(portIdx); |
| 8905 | portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(), |
| 8906 | port.getPhoneId(), true)); |
| 8907 | } else { |
| 8908 | portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false)); |
| 8909 | } |
| 8910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8911 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8912 | slot.isEuicc(), |
| 8913 | cardId, |
| 8914 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8915 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8916 | slot.isRemovable(), portInfos); |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8917 | //setting the value after compatibility check |
| 8918 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8919 | } |
| 8920 | return infos; |
| 8921 | } finally { |
| 8922 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8923 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8924 | } |
| 8925 | |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8926 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 8927 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 8928 | boolean hasReadPermission) { |
| 8929 | String iccId = slot.getIccId(portIndex); |
| 8930 | if (hasReadPermission) { // if has read permission |
| 8931 | return iccId; |
| 8932 | } else { |
| 8933 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 8934 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 8935 | // if no read permission, checking carrier privilege access |
| 8936 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8937 | return iccId; |
| 8938 | } |
| 8939 | } |
| 8940 | } |
| 8941 | // No read permission or carrier privilege access. |
| 8942 | return UiccPortInfo.ICCID_REDACTED; |
| 8943 | } |
| 8944 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8945 | @Override |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8946 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8947 | public boolean switchSlots(int[] physicalSlots) { |
| 8948 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8949 | |
| 8950 | final long identity = Binder.clearCallingIdentity(); |
| 8951 | try { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8952 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 8953 | for (int i = 0; i < physicalSlots.length; i++) { |
| 8954 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 8955 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 8956 | physicalSlots[i], i)); |
| 8957 | } |
| 8958 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8959 | } finally { |
| 8960 | Binder.restoreCallingIdentity(identity); |
| 8961 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8962 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8963 | |
| 8964 | @Override |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8965 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 8966 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 8967 | enforceModifyPermission(); |
| 8968 | |
| 8969 | final long identity = Binder.clearCallingIdentity(); |
| 8970 | try { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8971 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8972 | } finally { |
| 8973 | Binder.restoreCallingIdentity(identity); |
| 8974 | } |
| 8975 | } |
| 8976 | |
| 8977 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8978 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8979 | final long identity = Binder.clearCallingIdentity(); |
| 8980 | try { |
| 8981 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8982 | } finally { |
| 8983 | Binder.restoreCallingIdentity(identity); |
| 8984 | } |
| 8985 | } |
| 8986 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8987 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8988 | * A test API to reload the UICC profile. |
| 8989 | * |
| 8990 | * <p>Requires that the calling app has permission |
| 8991 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8992 | * @hide |
| 8993 | */ |
| 8994 | @Override |
| 8995 | public void refreshUiccProfile(int subId) { |
| 8996 | enforceModifyPermission(); |
| 8997 | |
| 8998 | final long identity = Binder.clearCallingIdentity(); |
| 8999 | try { |
| 9000 | Phone phone = getPhone(subId); |
| 9001 | if (phone == null) { |
| 9002 | return; |
| 9003 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9004 | UiccPort uiccPort = phone.getUiccPort(); |
| 9005 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9006 | return; |
| 9007 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9008 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9009 | if (uiccProfile == null) { |
| 9010 | return; |
| 9011 | } |
| 9012 | uiccProfile.refresh(); |
| 9013 | } finally { |
| 9014 | Binder.restoreCallingIdentity(identity); |
| 9015 | } |
| 9016 | } |
| 9017 | |
| 9018 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9019 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9020 | */ |
| 9021 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9022 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9023 | } |
| 9024 | |
| 9025 | /** |
| 9026 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9027 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9028 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9029 | */ |
| 9030 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9031 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9032 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9033 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9034 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9035 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9036 | return isDataRoamingEnabled; |
| 9037 | } |
| 9038 | |
| 9039 | /** |
| 9040 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9041 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9042 | */ |
| 9043 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9044 | List<Integer> list = TelephonyProperties.default_network(); |
| 9045 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9046 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9047 | return list.get(phoneId); |
| 9048 | } |
| 9049 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9050 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9051 | |
| 9052 | @Override |
| 9053 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9054 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9055 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9056 | |
| 9057 | final long identity = Binder.clearCallingIdentity(); |
| 9058 | try { |
| 9059 | final Phone phone = getPhone(subId); |
| 9060 | if (phone == null) { |
| 9061 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9062 | return; |
| 9063 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9064 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9065 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9066 | if (carrierPrivilegeRules == null) { |
| 9067 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9068 | } else { |
| 9069 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9070 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9071 | } finally { |
| 9072 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9073 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | @Override |
| 9077 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9078 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9079 | |
| 9080 | final long identity = Binder.clearCallingIdentity(); |
| 9081 | try { |
| 9082 | final Phone phone = getPhone(subId); |
| 9083 | if (phone == null) { |
| 9084 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9085 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9086 | } |
| 9087 | return phone.getCarrierIdListVersion(); |
| 9088 | } finally { |
| 9089 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9090 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9091 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9092 | |
| 9093 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9094 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9095 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9096 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9097 | mApp, subId, callingPackage, callingFeatureId, |
| 9098 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9099 | return -1; |
| 9100 | } |
| 9101 | |
| 9102 | final long identity = Binder.clearCallingIdentity(); |
| 9103 | try { |
| 9104 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9105 | } finally { |
| 9106 | Binder.restoreCallingIdentity(identity); |
| 9107 | } |
| 9108 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9109 | |
| 9110 | @Override |
| 9111 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9112 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9113 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9114 | mApp, subId, "getCdmaRoamingMode"); |
| 9115 | |
| 9116 | final long identity = Binder.clearCallingIdentity(); |
| 9117 | try { |
| 9118 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9119 | } finally { |
| 9120 | Binder.restoreCallingIdentity(identity); |
| 9121 | } |
| 9122 | } |
| 9123 | |
| 9124 | @Override |
| 9125 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9127 | mApp, subId, "setCdmaRoamingMode"); |
| 9128 | |
| 9129 | final long identity = Binder.clearCallingIdentity(); |
| 9130 | try { |
| 9131 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9138 | public int getCdmaSubscriptionMode(int subId) { |
| 9139 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9140 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9141 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9142 | |
| 9143 | final long identity = Binder.clearCallingIdentity(); |
| 9144 | try { |
| 9145 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9146 | } finally { |
| 9147 | Binder.restoreCallingIdentity(identity); |
| 9148 | } |
| 9149 | } |
| 9150 | |
| 9151 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9152 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9154 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9155 | |
| 9156 | final long identity = Binder.clearCallingIdentity(); |
| 9157 | try { |
| 9158 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9159 | } finally { |
| 9160 | Binder.restoreCallingIdentity(identity); |
| 9161 | } |
| 9162 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9163 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9164 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9165 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9166 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9167 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9168 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9169 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9170 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9171 | } |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
| 9173 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9174 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9175 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9176 | if (phone.getEmergencyNumberTracker() != null |
| 9177 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9178 | emergencyNumberListInternal.put( |
| 9179 | phone.getSubId(), |
| 9180 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9181 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9182 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9183 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9184 | } finally { |
| 9185 | Binder.restoreCallingIdentity(identity); |
| 9186 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9187 | } |
| 9188 | |
| 9189 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9190 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9191 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9192 | if (!exactMatch) { |
| 9193 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9194 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9195 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9196 | } |
| 9197 | final long identity = Binder.clearCallingIdentity(); |
| 9198 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9199 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9200 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9201 | && phone.getEmergencyNumberTracker() |
| 9202 | .isEmergencyNumber(number, exactMatch)) { |
| 9203 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9204 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9205 | } |
| 9206 | return false; |
| 9207 | } finally { |
| 9208 | Binder.restoreCallingIdentity(identity); |
| 9209 | } |
| 9210 | } |
| 9211 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9212 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9213 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9214 | */ |
| 9215 | @Override |
| 9216 | public void startEmergencyCallbackMode() { |
| 9217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9218 | "startEmergencyCallbackMode"); |
| 9219 | enforceModifyPermission(); |
| 9220 | final long identity = Binder.clearCallingIdentity(); |
| 9221 | try { |
| 9222 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9223 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9224 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9225 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9226 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9227 | gsmCdmaPhone.obtainMessage( |
| 9228 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9229 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9230 | } |
| 9231 | } |
| 9232 | } finally { |
| 9233 | Binder.restoreCallingIdentity(identity); |
| 9234 | } |
| 9235 | } |
| 9236 | |
| 9237 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9238 | * Update emergency number list for test mode. |
| 9239 | */ |
| 9240 | @Override |
| 9241 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9242 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9243 | "updateEmergencyNumberListTestMode"); |
| 9244 | |
| 9245 | final long identity = Binder.clearCallingIdentity(); |
| 9246 | try { |
| 9247 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9248 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9249 | if (tracker != null) { |
| 9250 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9251 | } |
| 9252 | } |
| 9253 | } finally { |
| 9254 | Binder.restoreCallingIdentity(identity); |
| 9255 | } |
| 9256 | } |
| 9257 | |
| 9258 | /** |
| 9259 | * Get the full emergency number list for test mode. |
| 9260 | */ |
| 9261 | @Override |
| 9262 | public List<String> getEmergencyNumberListTestMode() { |
| 9263 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9264 | "getEmergencyNumberListTestMode"); |
| 9265 | |
| 9266 | final long identity = Binder.clearCallingIdentity(); |
| 9267 | try { |
| 9268 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9269 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9270 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9271 | if (tracker != null) { |
| 9272 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9273 | emergencyNumbers.add(num.getNumber()); |
| 9274 | } |
| 9275 | } |
| 9276 | } |
| 9277 | return new ArrayList<>(emergencyNumbers); |
| 9278 | } finally { |
| 9279 | Binder.restoreCallingIdentity(identity); |
| 9280 | } |
| 9281 | } |
| 9282 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9283 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9284 | public int getEmergencyNumberDbVersion(int subId) { |
| 9285 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9286 | |
| 9287 | final long identity = Binder.clearCallingIdentity(); |
| 9288 | try { |
| 9289 | final Phone phone = getPhone(subId); |
| 9290 | if (phone == null) { |
| 9291 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9292 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9293 | } |
| 9294 | return phone.getEmergencyNumberDbVersion(); |
| 9295 | } finally { |
| 9296 | Binder.restoreCallingIdentity(identity); |
| 9297 | } |
| 9298 | } |
| 9299 | |
| 9300 | @Override |
| 9301 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9302 | enforceModifyPermission(); |
| 9303 | |
| 9304 | final long identity = Binder.clearCallingIdentity(); |
| 9305 | try { |
| 9306 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9307 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9308 | if (tracker != null) { |
| 9309 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9310 | } |
| 9311 | } |
| 9312 | } finally { |
| 9313 | Binder.restoreCallingIdentity(identity); |
| 9314 | } |
| 9315 | } |
| 9316 | |
| 9317 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9318 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9319 | enforceActiveEmergencySessionPermission(); |
| 9320 | |
| 9321 | final long identity = Binder.clearCallingIdentity(); |
| 9322 | try { |
| 9323 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9324 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9325 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9326 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9327 | } |
| 9328 | } |
| 9329 | } finally { |
| 9330 | Binder.restoreCallingIdentity(identity); |
| 9331 | } |
| 9332 | } |
| 9333 | |
| 9334 | @Override |
| 9335 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9336 | enforceActiveEmergencySessionPermission(); |
| 9337 | |
| 9338 | final long identity = Binder.clearCallingIdentity(); |
| 9339 | try { |
| 9340 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9341 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9342 | if (tracker != null) { |
| 9343 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9344 | } |
| 9345 | } |
| 9346 | } finally { |
| 9347 | Binder.restoreCallingIdentity(identity); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9352 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9353 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9354 | Phone phone = getPhone(subId); |
| 9355 | if (phone == null) { |
| 9356 | return null; |
| 9357 | } |
| 9358 | final long identity = Binder.clearCallingIdentity(); |
| 9359 | try { |
| 9360 | UiccProfile profile = UiccController.getInstance() |
| 9361 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9362 | if (profile != null) { |
| 9363 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9364 | } |
| 9365 | } finally { |
| 9366 | Binder.restoreCallingIdentity(identity); |
| 9367 | } |
| 9368 | return null; |
| 9369 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9370 | |
| 9371 | /** |
| 9372 | * Enable or disable a modem stack. |
| 9373 | */ |
| 9374 | @Override |
| 9375 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9376 | enforceModifyPermission(); |
| 9377 | |
| 9378 | final long identity = Binder.clearCallingIdentity(); |
| 9379 | try { |
| 9380 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9381 | if (phone == null) { |
| 9382 | return false; |
| 9383 | } else { |
| 9384 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9385 | } |
| 9386 | } finally { |
| 9387 | Binder.restoreCallingIdentity(identity); |
| 9388 | } |
| 9389 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9390 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9391 | /** |
| 9392 | * Whether a modem stack is enabled or not. |
| 9393 | */ |
| 9394 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9395 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9396 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9397 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9398 | if (phone == null) return false; |
| 9399 | |
| 9400 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9401 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9402 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9403 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9404 | } |
| 9405 | |
| 9406 | final long identity = Binder.clearCallingIdentity(); |
| 9407 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9408 | try { |
| 9409 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9410 | } catch (NoSuchElementException ex) { |
| 9411 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9412 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9413 | } finally { |
| 9414 | Binder.restoreCallingIdentity(identity); |
| 9415 | } |
| 9416 | } |
| 9417 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9418 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9419 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9420 | enforceModifyPermission(); |
| 9421 | |
| 9422 | final long identity = Binder.clearCallingIdentity(); |
| 9423 | try { |
| 9424 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9425 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9426 | .commit(); |
| 9427 | } finally { |
| 9428 | Binder.restoreCallingIdentity(identity); |
| 9429 | } |
| 9430 | } |
| 9431 | |
| 9432 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9433 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9434 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9435 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9436 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9437 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9438 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9439 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9440 | |
| 9441 | final long identity = Binder.clearCallingIdentity(); |
| 9442 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9443 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9444 | } finally { |
| 9445 | Binder.restoreCallingIdentity(identity); |
| 9446 | } |
| 9447 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9448 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9449 | @TelephonyManager.IsMultiSimSupportedResult |
| 9450 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9451 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9452 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9453 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9454 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9455 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9456 | } |
| 9457 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9458 | // supported by the modem, indicate that it is restricted. |
| 9459 | PhoneCapability staticCapability = |
| 9460 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9461 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9462 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9463 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9464 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9465 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9466 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9467 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9468 | } |
| 9469 | // Check if support of multiple SIMs is restricted by carrier |
| 9470 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9471 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9472 | } |
| 9473 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9474 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9475 | } |
| 9476 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9477 | /** |
| 9478 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9479 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9480 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9481 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9482 | * @param numOfSims number of active sims we want to switch to |
| 9483 | */ |
| 9484 | @Override |
| 9485 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9486 | if (numOfSims == 1) { |
| 9487 | enforceModifyPermission(); |
| 9488 | } else { |
| 9489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9490 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9491 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9492 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9493 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9494 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9495 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9496 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9497 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9498 | return; |
| 9499 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9500 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9501 | } finally { |
| 9502 | Binder.restoreCallingIdentity(identity); |
| 9503 | } |
| 9504 | } |
| 9505 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9506 | @Override |
| 9507 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9508 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9509 | Phone phone = getPhone(subId); |
| 9510 | if (phone == null) { |
| 9511 | return false; |
| 9512 | } |
| 9513 | final long identity = Binder.clearCallingIdentity(); |
| 9514 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9515 | UiccPort uiccPort = phone.getUiccPort(); |
| 9516 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9517 | return false; |
| 9518 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9519 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9520 | if (uiccProfile == null) { |
| 9521 | return false; |
| 9522 | } |
| 9523 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9524 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9525 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9526 | } |
| 9527 | return false; |
| 9528 | } finally { |
| 9529 | Binder.restoreCallingIdentity(identity); |
| 9530 | } |
| 9531 | } |
| 9532 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9533 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9534 | * Get whether making changes to modem configurations will trigger reboot. |
| 9535 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9536 | */ |
| 9537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9538 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9539 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9540 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9541 | mApp, subId, callingPackage, callingFeatureId, |
| 9542 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9543 | return false; |
| 9544 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | try { |
| 9547 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9548 | } finally { |
| 9549 | Binder.restoreCallingIdentity(identity); |
| 9550 | } |
| 9551 | } |
| 9552 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9553 | private void updateModemStateMetrics() { |
| 9554 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9555 | // TODO: check the state for each modem if the api is ready. |
| 9556 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9557 | } |
| 9558 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9559 | @Override |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9560 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9561 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9562 | // Verify that the callingPackage belongs to the calling UID |
| 9563 | mApp.getSystemService(AppOpsManager.class) |
| 9564 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9565 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9566 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9567 | try { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9568 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9569 | if (slotInfos != null) { |
| 9570 | for (int i = 0; i < slotInfos.length; i++) { |
| 9571 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9572 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9573 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9574 | portInfo.getLogicalSlotIndex())); |
| 9575 | } |
| 9576 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9577 | } |
| 9578 | } |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9579 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9580 | } finally { |
| 9581 | Binder.restoreCallingIdentity(identity); |
| 9582 | } |
| 9583 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9584 | |
| 9585 | /** |
| 9586 | * Get the IRadio HAL Version |
| 9587 | */ |
| 9588 | @Override |
| 9589 | public int getRadioHalVersion() { |
| 9590 | Phone phone = getDefaultPhone(); |
| 9591 | if (phone == null) return -1; |
| 9592 | HalVersion hv = phone.getHalVersion(); |
| 9593 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9594 | return hv.major * 100 + hv.minor; |
| 9595 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9596 | |
| 9597 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9598 | * Get the current calling package name. |
| 9599 | * @return the current calling package name |
| 9600 | */ |
| 9601 | @Override |
| 9602 | public String getCurrentPackageName() { |
| 9603 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9604 | } |
| 9605 | |
| 9606 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9607 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9608 | * corresponding network requests on a subId. |
| 9609 | * |
| 9610 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9611 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9612 | * 2) APN is un-metered for this subscription, or |
| 9613 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9614 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9615 | * |
| 9616 | * @return whether data is allowed for a apn type. |
| 9617 | * |
| 9618 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9619 | */ |
| 9620 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9621 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9622 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9623 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9624 | |
| 9625 | // Now that all security checks passes, perform the operation as ourselves. |
| 9626 | final long identity = Binder.clearCallingIdentity(); |
| 9627 | try { |
| 9628 | Phone phone = getPhone(subId); |
| 9629 | if (phone == null) return false; |
| 9630 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9631 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9632 | boolean isDataEnabled; |
| 9633 | if (phone.isUsingNewDataStack()) { |
| 9634 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9635 | } else { |
| 9636 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9637 | } |
| 9638 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9639 | } finally { |
| 9640 | Binder.restoreCallingIdentity(identity); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9645 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9646 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9647 | |
| 9648 | // Now that all security checks passes, perform the operation as ourselves. |
| 9649 | final long identity = Binder.clearCallingIdentity(); |
| 9650 | try { |
| 9651 | Phone phone = getPhone(subId); |
| 9652 | if (phone == null) return true; // By default return true. |
| 9653 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9654 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9655 | } finally { |
| 9656 | Binder.restoreCallingIdentity(identity); |
| 9657 | } |
| 9658 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9659 | |
| 9660 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9661 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9662 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9663 | enforceModifyPermission(); |
| 9664 | long token = Binder.clearCallingIdentity(); |
| 9665 | try { |
| 9666 | Phone phone = getPhone(subscriptionId); |
| 9667 | if (phone == null) { |
| 9668 | try { |
| 9669 | if (resultCallback != null) { |
| 9670 | resultCallback.accept(false); |
| 9671 | } |
| 9672 | } catch (RemoteException e) { |
| 9673 | // ignore |
| 9674 | } |
| 9675 | return; |
| 9676 | } |
| 9677 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9678 | Pair.create(specifiers, (x) -> { |
| 9679 | try { |
| 9680 | if (resultCallback != null) { |
| 9681 | resultCallback.accept(x); |
| 9682 | } |
| 9683 | } catch (RemoteException e) { |
| 9684 | // ignore |
| 9685 | } |
| 9686 | }); |
| 9687 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9688 | } finally { |
| 9689 | Binder.restoreCallingIdentity(token); |
| 9690 | } |
| 9691 | } |
| 9692 | |
| 9693 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9694 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9695 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9696 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9697 | mApp, subId, "getSystemSelectionChannels"); |
| 9698 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9699 | final long identity = Binder.clearCallingIdentity(); |
| 9700 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9701 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9702 | if (result instanceof IllegalStateException) { |
| 9703 | throw (IllegalStateException) result; |
| 9704 | } |
| 9705 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9706 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9707 | return specifiers; |
| 9708 | } finally { |
| 9709 | Binder.restoreCallingIdentity(identity); |
| 9710 | } |
| 9711 | } |
| 9712 | |
| 9713 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9714 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9715 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9716 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9717 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9718 | if (iccRecords == null) { |
| 9719 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9720 | return false; |
| 9721 | } |
| 9722 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9723 | } |
| 9724 | |
| 9725 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9726 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9727 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9728 | if (callingPackage == null) { |
| 9729 | callingPackage = getCurrentPackageName(); |
| 9730 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9731 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9732 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9733 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9734 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9735 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9736 | } |
| 9737 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9738 | Intent intent = new Intent(); |
| 9739 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9740 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9741 | // Bring up choose default SMS subscription dialog right now |
| 9742 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9743 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9744 | mApp.startActivity(intent); |
| 9745 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9746 | |
| 9747 | @Override |
| 9748 | public String getMmsUAProfUrl(int subId) { |
| 9749 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9750 | final long identity = Binder.clearCallingIdentity(); |
| 9751 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9752 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9753 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9754 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9755 | return carrierUAProfUrl; |
| 9756 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9757 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9758 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9759 | } finally { |
| 9760 | Binder.restoreCallingIdentity(identity); |
| 9761 | } |
| 9762 | } |
| 9763 | |
| 9764 | @Override |
| 9765 | public String getMmsUserAgent(int subId) { |
| 9766 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9767 | final long identity = Binder.clearCallingIdentity(); |
| 9768 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9769 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9770 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9771 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9772 | return carrierUserAgent; |
| 9773 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9774 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9775 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9776 | } finally { |
| 9777 | Binder.restoreCallingIdentity(identity); |
| 9778 | } |
| 9779 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9780 | |
| 9781 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9782 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9783 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9784 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9785 | final long identity = Binder.clearCallingIdentity(); |
| 9786 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9787 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9788 | if (phone == null) return false; |
| 9789 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9790 | switch (policy) { |
| 9791 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9792 | if (phone.isUsingNewDataStack()) { |
| 9793 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9794 | } else { |
| 9795 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9796 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9797 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9798 | if (phone.isUsingNewDataStack()) { |
| 9799 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9800 | } else { |
| 9801 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9802 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9803 | default: |
| 9804 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9805 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9806 | } finally { |
| 9807 | Binder.restoreCallingIdentity(identity); |
| 9808 | } |
| 9809 | } |
| 9810 | |
| 9811 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9812 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9813 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9814 | enforceModifyPermission(); |
| 9815 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9816 | final long identity = Binder.clearCallingIdentity(); |
| 9817 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9818 | Phone phone = getPhone(subscriptionId); |
| 9819 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9820 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9821 | switch (policy) { |
| 9822 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9823 | if (phone.isUsingNewDataStack()) { |
| 9824 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9825 | } else { |
| 9826 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9827 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9828 | break; |
| 9829 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9830 | if (phone.isUsingNewDataStack()) { |
| 9831 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9832 | } else { |
| 9833 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9834 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9835 | break; |
| 9836 | default: |
| 9837 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9838 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9839 | } finally { |
| 9840 | Binder.restoreCallingIdentity(identity); |
| 9841 | } |
| 9842 | } |
| 9843 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9844 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9845 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9846 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9847 | * otherwise. |
| 9848 | */ |
| 9849 | @Override |
| 9850 | public void setCepEnabled(boolean isCepEnabled) { |
| 9851 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9852 | |
| 9853 | final long identity = Binder.clearCallingIdentity(); |
| 9854 | try { |
| 9855 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9856 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9857 | Phone defaultPhone = phone.getImsPhone(); |
| 9858 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9859 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9860 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9861 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9862 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9863 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9864 | + imsPhone.getMsisdn()); |
| 9865 | } |
| 9866 | } |
| 9867 | } finally { |
| 9868 | Binder.restoreCallingIdentity(identity); |
| 9869 | } |
| 9870 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9871 | |
| 9872 | /** |
| 9873 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9874 | * |
| 9875 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9876 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9877 | * before being read. |
| 9878 | */ |
| 9879 | @Override |
| 9880 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9881 | isCompressed) { |
| 9882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9883 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9884 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9885 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9886 | } |
| 9887 | if (!isImsAvailableOnDevice()) { |
| 9888 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9889 | "IMS not available on device."); |
| 9890 | } |
| 9891 | |
| 9892 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9893 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9894 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9895 | } finally { |
| 9896 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9897 | } |
| 9898 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9899 | |
| 9900 | @Override |
| 9901 | public boolean isIccLockEnabled(int subId) { |
| 9902 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9903 | |
| 9904 | // Now that all security checks passes, perform the operation as ourselves. |
| 9905 | final long identity = Binder.clearCallingIdentity(); |
| 9906 | try { |
| 9907 | Phone phone = getPhone(subId); |
| 9908 | if (phone != null && phone.getIccCard() != null) { |
| 9909 | return phone.getIccCard().getIccLockEnabled(); |
| 9910 | } else { |
| 9911 | return false; |
| 9912 | } |
| 9913 | } finally { |
| 9914 | Binder.restoreCallingIdentity(identity); |
| 9915 | } |
| 9916 | } |
| 9917 | |
| 9918 | /** |
| 9919 | * Set the ICC pin lock enabled or disabled. |
| 9920 | * |
| 9921 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9922 | * three cases: |
| 9923 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9924 | * successfully. |
| 9925 | * - Positive number and zero for remaining password attempts. |
| 9926 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9927 | * |
| 9928 | */ |
| 9929 | @Override |
| 9930 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9931 | enforceModifyPermission(); |
| 9932 | |
| 9933 | Phone phone = getPhone(subId); |
| 9934 | if (phone == null) { |
| 9935 | return 0; |
| 9936 | } |
| 9937 | // Now that all security checks passes, perform the operation as ourselves. |
| 9938 | final long identity = Binder.clearCallingIdentity(); |
| 9939 | try { |
| 9940 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9941 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9942 | return attemptsRemaining; |
| 9943 | |
| 9944 | } catch (Exception e) { |
| 9945 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9946 | } finally { |
| 9947 | Binder.restoreCallingIdentity(identity); |
| 9948 | } |
| 9949 | return 0; |
| 9950 | } |
| 9951 | |
| 9952 | /** |
| 9953 | * Change the ICC password used in ICC pin lock. |
| 9954 | * |
| 9955 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9956 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9957 | * - Positive number and zero for remaining password attempts. |
| 9958 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9959 | * |
| 9960 | */ |
| 9961 | @Override |
| 9962 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9963 | enforceModifyPermission(); |
| 9964 | |
| 9965 | Phone phone = getPhone(subId); |
| 9966 | if (phone == null) { |
| 9967 | return 0; |
| 9968 | } |
| 9969 | // Now that all security checks passes, perform the operation as ourselves. |
| 9970 | final long identity = Binder.clearCallingIdentity(); |
| 9971 | try { |
| 9972 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9973 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9974 | return attemptsRemaining; |
| 9975 | |
| 9976 | } catch (Exception e) { |
| 9977 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9978 | } finally { |
| 9979 | Binder.restoreCallingIdentity(identity); |
| 9980 | } |
| 9981 | return 0; |
| 9982 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9983 | |
| 9984 | /** |
| 9985 | * Request for receiving user activity notification |
| 9986 | */ |
| 9987 | @Override |
| 9988 | public void requestUserActivityNotification() { |
| 9989 | if (!mNotifyUserActivity.get() |
| 9990 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9991 | mNotifyUserActivity.set(true); |
| 9992 | } |
| 9993 | } |
| 9994 | |
| 9995 | /** |
| 9996 | * Called when userActivity is signalled in the power manager. |
| 9997 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9998 | */ |
| 9999 | @Override |
| 10000 | public void userActivity() { |
| 10001 | // *************************************** |
| 10002 | // * Inherited from PhoneWindowManager * |
| 10003 | // *************************************** |
| 10004 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10005 | // WITH ITS LOCKS HELD. |
| 10006 | // |
| 10007 | // This code must be VERY careful about the locks |
| 10008 | // it acquires. |
| 10009 | // In fact, the current code acquires way too many, |
| 10010 | // and probably has lurking deadlocks. |
| 10011 | |
| 10012 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10013 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10014 | } |
| 10015 | |
| 10016 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10017 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10018 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10019 | } |
| 10020 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10021 | |
| 10022 | @Override |
| 10023 | public boolean canConnectTo5GInDsdsMode() { |
| 10024 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10025 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10026 | |
| 10027 | @Override |
| 10028 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10029 | String callingFeatureId) { |
| 10030 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10031 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10032 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10033 | } |
| 10034 | |
| 10035 | Phone phone = getPhone(subId); |
| 10036 | if (phone == null) { |
| 10037 | throw new RuntimeException("phone is not available"); |
| 10038 | } |
| 10039 | // Now that all security checks passes, perform the operation as ourselves. |
| 10040 | final long identity = Binder.clearCallingIdentity(); |
| 10041 | try { |
| 10042 | return phone.getEquivalentHomePlmns(); |
| 10043 | } finally { |
| 10044 | Binder.restoreCallingIdentity(identity); |
| 10045 | } |
| 10046 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10047 | |
| 10048 | @Override |
| 10049 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10050 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10051 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10052 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10053 | if (radioInterfaceCapabilities == null) { |
| 10054 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10055 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10056 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10057 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10058 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10059 | @Override |
| 10060 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10061 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10062 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10063 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10064 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10065 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10066 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10067 | if (DBG) { |
| 10068 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10069 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10070 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10071 | } |
| 10072 | |
| 10073 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10074 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10075 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10076 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10077 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10078 | if (callback != null) { |
| 10079 | try { |
| 10080 | callback.onAuthenticationFailure( |
| 10081 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10082 | } catch (RemoteException exception) { |
| 10083 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10084 | } |
| 10085 | return; |
| 10086 | } |
| 10087 | } |
| 10088 | |
| 10089 | final long token = Binder.clearCallingIdentity(); |
| 10090 | try { |
| 10091 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10092 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10093 | forceBootStrapping, callback)); |
| 10094 | } finally { |
| 10095 | Binder.restoreCallingIdentity(token); |
| 10096 | } |
| 10097 | } |
| 10098 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10099 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10100 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10101 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10102 | * requested radio power state will actually be set. See {@link |
| 10103 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10104 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10105 | * @param enable {@code true} if trying to turn radio on. |
| 10106 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10107 | * false}. |
| 10108 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10109 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10110 | boolean isPhoneAvailable = false; |
| 10111 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10112 | Phone phone = PhoneFactory.getPhone(i); |
| 10113 | if (phone != null) { |
| 10114 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10115 | isPhoneAvailable = true; |
| 10116 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10117 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10118 | |
| 10119 | // return true if successfully informed the phone object about the thermal radio power |
| 10120 | // request. |
| 10121 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10122 | } |
| 10123 | |
| 10124 | private int handleDataThrottlingRequest(int subId, |
| 10125 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10126 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10127 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10128 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10129 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10130 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10131 | } |
| 10132 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10133 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10134 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10135 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10136 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10137 | } |
| 10138 | |
| 10139 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10140 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10141 | if (isDataThrottlingSupported) { |
| 10142 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10143 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10144 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10145 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10146 | } else if (thermalMitigationResult |
| 10147 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10148 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10149 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10150 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10151 | } |
| 10152 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10153 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10154 | |
| 10155 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10156 | } |
| 10157 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10158 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10159 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10160 | for (String pckg : context.getResources() |
| 10161 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10162 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10163 | } |
| 10164 | } |
| 10165 | |
| 10166 | return sThermalMitigationAllowlistedPackages; |
| 10167 | } |
| 10168 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10169 | private boolean isAnyPhoneInEmergencyState() { |
| 10170 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10171 | if (tm.isInEmergencyCall()) { |
| 10172 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10173 | return true; |
| 10174 | } |
| 10175 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10176 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10177 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10178 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10179 | + phone.isInEcm()); |
| 10180 | return true; |
| 10181 | } |
| 10182 | } |
| 10183 | |
| 10184 | return false; |
| 10185 | } |
| 10186 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10187 | /** |
| 10188 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10189 | * @param packageName name of package to be allowlisted |
| 10190 | * @param context |
| 10191 | */ |
| 10192 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10193 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10194 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10195 | } |
| 10196 | |
| 10197 | /** |
| 10198 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10199 | * @param packageName name of package to remove from allowlist |
| 10200 | * @param context |
| 10201 | */ |
| 10202 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10203 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10204 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10205 | } |
| 10206 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10207 | /** |
| 10208 | * Thermal mitigation request to control functionalities at modem. |
| 10209 | * |
| 10210 | * @param subId the id of the subscription. |
| 10211 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10212 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10213 | * |
| 10214 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10215 | */ |
| 10216 | @Override |
| 10217 | @ThermalMitigationResult |
| 10218 | public int sendThermalMitigationRequest( |
| 10219 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10220 | ThermalMitigationRequest thermalMitigationRequest, |
| 10221 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10222 | enforceModifyPermission(); |
| 10223 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10224 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10225 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10226 | .contains(callingPackage)) { |
| 10227 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10228 | + "calling package: " + callingPackage); |
| 10229 | } |
| 10230 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10231 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10232 | final long identity = Binder.clearCallingIdentity(); |
| 10233 | |
| 10234 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10235 | try { |
| 10236 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10237 | switch (thermalMitigationAction) { |
| 10238 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10239 | thermalMitigationResult = |
| 10240 | handleDataThrottlingRequest(subId, |
| 10241 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10242 | break; |
| 10243 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10244 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10245 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10246 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10247 | } |
| 10248 | |
| 10249 | // Ensure that radio is on. If not able to power on due to phone being |
| 10250 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10251 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10252 | thermalMitigationResult = |
| 10253 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10254 | break; |
| 10255 | } |
| 10256 | |
| 10257 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10258 | false); |
| 10259 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10260 | break; |
| 10261 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10262 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10263 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10264 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10265 | } |
| 10266 | |
| 10267 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10268 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10269 | Phone phone = getPhone(subId); |
| 10270 | if (phone == null) { |
| 10271 | thermalMitigationResult = |
| 10272 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10273 | break; |
| 10274 | } |
| 10275 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10276 | TelephonyConnectionService service = |
| 10277 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10278 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10279 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10280 | thermalMitigationResult = |
| 10281 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10282 | break; |
| 10283 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10284 | thermalMitigationResult = |
| 10285 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10286 | break; |
| 10287 | } |
| 10288 | } else { |
| 10289 | thermalMitigationResult = |
| 10290 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10291 | break; |
| 10292 | } |
| 10293 | |
| 10294 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10295 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10296 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10297 | thermalMitigationResult = |
| 10298 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10299 | break; |
| 10300 | } |
| 10301 | thermalMitigationResult = |
| 10302 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10303 | break; |
| 10304 | default: |
| 10305 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10306 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10307 | } |
| 10308 | } catch (IllegalArgumentException e) { |
| 10309 | throw e; |
| 10310 | } catch (Exception e) { |
| 10311 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10312 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10313 | } finally { |
| 10314 | Binder.restoreCallingIdentity(identity); |
| 10315 | } |
| 10316 | |
| 10317 | if (DBG) { |
| 10318 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10319 | + thermalMitigationResult); |
| 10320 | } |
| 10321 | |
| 10322 | return thermalMitigationResult; |
| 10323 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10324 | |
| 10325 | /** |
| 10326 | * Set the GbaService Package Name that Telephony will bind to. |
| 10327 | * |
| 10328 | * @param subId The sim that the GbaService is associated with. |
| 10329 | * @param packageName The name of the package to be replaced with. |
| 10330 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10331 | */ |
| 10332 | @Override |
| 10333 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10334 | enforceModifyPermission(); |
| 10335 | |
| 10336 | final long identity = Binder.clearCallingIdentity(); |
| 10337 | try { |
| 10338 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10339 | } finally { |
| 10340 | Binder.restoreCallingIdentity(identity); |
| 10341 | } |
| 10342 | } |
| 10343 | |
| 10344 | /** |
| 10345 | * Return the package name of the currently bound GbaService. |
| 10346 | * |
| 10347 | * @param subId The sim that the GbaService is associated with. |
| 10348 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10349 | */ |
| 10350 | @Override |
| 10351 | public String getBoundGbaService(int subId) { |
| 10352 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10353 | |
| 10354 | final long identity = Binder.clearCallingIdentity(); |
| 10355 | try { |
| 10356 | return getGbaManager(subId).getServicePackage(); |
| 10357 | } finally { |
| 10358 | Binder.restoreCallingIdentity(identity); |
| 10359 | } |
| 10360 | } |
| 10361 | |
| 10362 | /** |
| 10363 | * Set the release time for telephony to unbind GbaService. |
| 10364 | * |
| 10365 | * @param subId The sim that the GbaService is associated with. |
| 10366 | * @param interval The release time to unbind GbaService by millisecond. |
| 10367 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10368 | */ |
| 10369 | @Override |
| 10370 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10371 | enforceModifyPermission(); |
| 10372 | |
| 10373 | final long identity = Binder.clearCallingIdentity(); |
| 10374 | try { |
| 10375 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10376 | } finally { |
| 10377 | Binder.restoreCallingIdentity(identity); |
| 10378 | } |
| 10379 | } |
| 10380 | |
| 10381 | /** |
| 10382 | * Return the release time for telephony to unbind GbaService. |
| 10383 | * |
| 10384 | * @param subId The sim that the GbaService is associated with. |
| 10385 | * @return The release time to unbind GbaService by millisecond. |
| 10386 | */ |
| 10387 | @Override |
| 10388 | public int getGbaReleaseTime(int subId) { |
| 10389 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10390 | |
| 10391 | final long identity = Binder.clearCallingIdentity(); |
| 10392 | try { |
| 10393 | return getGbaManager(subId).getReleaseTime(); |
| 10394 | } finally { |
| 10395 | Binder.restoreCallingIdentity(identity); |
| 10396 | } |
| 10397 | } |
| 10398 | |
| 10399 | private GbaManager getGbaManager(int subId) { |
| 10400 | GbaManager instance = GbaManager.getInstance(subId); |
| 10401 | if (instance == null) { |
| 10402 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10403 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10404 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10405 | } |
| 10406 | return instance; |
| 10407 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10408 | |
| 10409 | /** |
| 10410 | * indicate whether the device and the carrier can support |
| 10411 | * RCS VoLTE single registration. |
| 10412 | */ |
| 10413 | @Override |
| 10414 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10415 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10416 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10417 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10418 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10419 | |
| 10420 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10421 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10422 | } |
| 10423 | |
| 10424 | final long identity = Binder.clearCallingIdentity(); |
| 10425 | try { |
| 10426 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10427 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10428 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10429 | if (isCapable != null) { |
| 10430 | return isCapable; |
| 10431 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10432 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10433 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10434 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10435 | } finally { |
| 10436 | Binder.restoreCallingIdentity(identity); |
| 10437 | } |
| 10438 | } |
| 10439 | |
| 10440 | /** |
| 10441 | * Register RCS provisioning callback. |
| 10442 | */ |
| 10443 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10444 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10445 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10446 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10447 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10448 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10449 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10450 | |
| 10451 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10452 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10453 | } |
| 10454 | if (!isImsAvailableOnDevice()) { |
| 10455 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10456 | "IMS not available on device."); |
| 10457 | } |
| 10458 | |
| 10459 | final long identity = Binder.clearCallingIdentity(); |
| 10460 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10461 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10462 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10463 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10464 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10465 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10466 | } finally { |
| 10467 | Binder.restoreCallingIdentity(identity); |
| 10468 | } |
| 10469 | } |
| 10470 | |
| 10471 | /** |
| 10472 | * Unregister RCS provisioning callback. |
| 10473 | */ |
| 10474 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10475 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10476 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10477 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10478 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10479 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10480 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10481 | |
| 10482 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10483 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10484 | } |
| 10485 | if (!isImsAvailableOnDevice()) { |
| 10486 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10487 | "IMS not available on device."); |
| 10488 | } |
| 10489 | |
| 10490 | final long identity = Binder.clearCallingIdentity(); |
| 10491 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10492 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10493 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10494 | } finally { |
| 10495 | Binder.restoreCallingIdentity(identity); |
| 10496 | } |
| 10497 | } |
| 10498 | |
| 10499 | /** |
| 10500 | * trigger RCS reconfiguration. |
| 10501 | */ |
| 10502 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10503 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10504 | "triggerRcsReconfiguration", |
| 10505 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10506 | |
| 10507 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10508 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10509 | } |
| 10510 | if (!isImsAvailableOnDevice()) { |
| 10511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10512 | "IMS not available on device."); |
| 10513 | } |
| 10514 | |
| 10515 | final long identity = Binder.clearCallingIdentity(); |
| 10516 | try { |
| 10517 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10518 | } finally { |
| 10519 | Binder.restoreCallingIdentity(identity); |
| 10520 | } |
| 10521 | } |
| 10522 | |
| 10523 | /** |
| 10524 | * Provide the client configuration parameters of the RCS application. |
| 10525 | */ |
| 10526 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10527 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10528 | "setRcsClientConfiguration", |
| 10529 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10530 | |
| 10531 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10532 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10533 | } |
| 10534 | if (!isImsAvailableOnDevice()) { |
| 10535 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10536 | "IMS not available on device."); |
| 10537 | } |
| 10538 | |
| 10539 | final long identity = Binder.clearCallingIdentity(); |
| 10540 | |
| 10541 | try { |
| 10542 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10543 | if (configBinder == null) { |
| 10544 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10545 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10546 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10547 | } else { |
| 10548 | configBinder.setRcsClientConfiguration(rcc); |
| 10549 | } |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10550 | |
| 10551 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10552 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10553 | } catch (RemoteException e) { |
| 10554 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10555 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10556 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10557 | } finally { |
| 10558 | Binder.restoreCallingIdentity(identity); |
| 10559 | } |
| 10560 | } |
| 10561 | |
| 10562 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10563 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10564 | */ |
| 10565 | @Override |
| 10566 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10567 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10568 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10569 | |
| 10570 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10571 | } |
| 10572 | |
| 10573 | /** |
| 10574 | * Gets the test mode for RCS VoLTE single registration. |
| 10575 | */ |
| 10576 | @Override |
| 10577 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10578 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10579 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10580 | |
| 10581 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10582 | } |
| 10583 | |
| 10584 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10585 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10586 | */ |
| 10587 | @Override |
| 10588 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10589 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10590 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10591 | enforceModifyPermission(); |
| 10592 | |
| 10593 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10594 | : Boolean.parseBoolean(enabledStr); |
| 10595 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10596 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10597 | } |
| 10598 | |
| 10599 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10600 | * Sends a device to device communication message. Only usable via shell. |
| 10601 | * @param message message to send. |
| 10602 | * @param value message value. |
| 10603 | */ |
| 10604 | @Override |
| 10605 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10606 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10607 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10608 | enforceModifyPermission(); |
| 10609 | |
| 10610 | final long identity = Binder.clearCallingIdentity(); |
| 10611 | try { |
| 10612 | TelephonyConnectionService service = |
| 10613 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10614 | if (service == null) { |
| 10615 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10616 | return; |
| 10617 | } |
| 10618 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10619 | } finally { |
| 10620 | Binder.restoreCallingIdentity(identity); |
| 10621 | } |
| 10622 | } |
| 10623 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10624 | /** |
| 10625 | * Sets the specified device to device transport active. |
| 10626 | * @param transport The transport to set active. |
| 10627 | */ |
| 10628 | @Override |
| 10629 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10630 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10631 | "setActiveDeviceToDeviceTransport"); |
| 10632 | enforceModifyPermission(); |
| 10633 | |
| 10634 | final long identity = Binder.clearCallingIdentity(); |
| 10635 | try { |
| 10636 | TelephonyConnectionService service = |
| 10637 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10638 | if (service == null) { |
| 10639 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10640 | return; |
| 10641 | } |
| 10642 | service.setActiveDeviceToDeviceTransport(transport); |
| 10643 | } finally { |
| 10644 | Binder.restoreCallingIdentity(identity); |
| 10645 | } |
| 10646 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10647 | |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10648 | @Override |
| 10649 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10650 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10651 | "setDeviceToDeviceForceEnabled"); |
| 10652 | |
| 10653 | final long identity = Binder.clearCallingIdentity(); |
| 10654 | try { |
| 10655 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10656 | p -> { |
| 10657 | Phone thePhone = p.getImsPhone(); |
| 10658 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10659 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10660 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10661 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10662 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10663 | (ImsPhoneCallTracker) tracker; |
| 10664 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10665 | } |
| 10666 | } |
| 10667 | } |
| 10668 | ); |
| 10669 | } finally { |
| 10670 | Binder.restoreCallingIdentity(identity); |
| 10671 | } |
| 10672 | } |
| 10673 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10674 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10675 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10676 | */ |
| 10677 | @Override |
| 10678 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10679 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10680 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10681 | } |
| 10682 | |
| 10683 | /** |
| 10684 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10685 | */ |
| 10686 | @Override |
| 10687 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10688 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10689 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10690 | enforceModifyPermission(); |
| 10691 | |
| 10692 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10693 | : Boolean.parseBoolean(enabledStr); |
| 10694 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10695 | subId, enabled); |
| 10696 | } |
| 10697 | |
| 10698 | /** |
| 10699 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10700 | */ |
| 10701 | @Override |
| 10702 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10703 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10704 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10705 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10706 | |
| 10707 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10708 | * Overrides the ims feature validation result |
| 10709 | */ |
| 10710 | @Override |
| 10711 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10712 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10713 | "setImsFeatureValidationOverride"); |
| 10714 | |
| 10715 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10716 | : Boolean.parseBoolean(enabledStr); |
| 10717 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10718 | subId, enabled); |
| 10719 | } |
| 10720 | |
| 10721 | /** |
| 10722 | * Gets the ims feature validation override value |
| 10723 | */ |
| 10724 | @Override |
| 10725 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10726 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10727 | "getImsFeatureValidationOverride"); |
| 10728 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10729 | } |
| 10730 | |
| 10731 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10732 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10733 | * their mobile plan. |
| 10734 | */ |
| 10735 | @Override |
| 10736 | public String getMobileProvisioningUrl() { |
| 10737 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10738 | final long identity = Binder.clearCallingIdentity(); |
| 10739 | try { |
| 10740 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10741 | } finally { |
| 10742 | Binder.restoreCallingIdentity(identity); |
| 10743 | } |
| 10744 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10745 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10746 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10747 | * Get the EAB contact from the EAB database. |
| 10748 | */ |
| 10749 | @Override |
| 10750 | public String getContactFromEab(String contact) { |
| 10751 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10752 | enforceModifyPermission(); |
| 10753 | final long identity = Binder.clearCallingIdentity(); |
| 10754 | try { |
| 10755 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10756 | } finally { |
| 10757 | Binder.restoreCallingIdentity(identity); |
| 10758 | } |
| 10759 | } |
| 10760 | |
| 10761 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10762 | * Get the EAB capability from the EAB database. |
| 10763 | */ |
| 10764 | @Override |
| 10765 | public String getCapabilityFromEab(String contact) { |
| 10766 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10767 | enforceModifyPermission(); |
| 10768 | final long identity = Binder.clearCallingIdentity(); |
| 10769 | try { |
| 10770 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10771 | } finally { |
| 10772 | Binder.restoreCallingIdentity(identity); |
| 10773 | } |
| 10774 | } |
| 10775 | |
| 10776 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10777 | * Remove the EAB contacts from the EAB database. |
| 10778 | */ |
| 10779 | @Override |
| 10780 | public int removeContactFromEab(int subId, String contacts) { |
| 10781 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10782 | enforceModifyPermission(); |
| 10783 | final long identity = Binder.clearCallingIdentity(); |
| 10784 | try { |
| 10785 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10786 | } finally { |
| 10787 | Binder.restoreCallingIdentity(identity); |
| 10788 | } |
| 10789 | } |
| 10790 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10791 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10792 | public boolean getDeviceUceEnabled() { |
| 10793 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10794 | final long identity = Binder.clearCallingIdentity(); |
| 10795 | try { |
| 10796 | return mApp.getDeviceUceEnabled(); |
| 10797 | } finally { |
| 10798 | Binder.restoreCallingIdentity(identity); |
| 10799 | } |
| 10800 | } |
| 10801 | |
| 10802 | @Override |
| 10803 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10804 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10805 | final long identity = Binder.clearCallingIdentity(); |
| 10806 | try { |
| 10807 | mApp.setDeviceUceEnabled(isEnabled); |
| 10808 | } finally { |
| 10809 | Binder.restoreCallingIdentity(identity); |
| 10810 | } |
| 10811 | } |
| 10812 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10813 | /** |
| 10814 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10815 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10816 | */ |
| 10817 | // Used for SHELL command only right now. |
| 10818 | @Override |
| 10819 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10820 | List<String> featureTags) { |
| 10821 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10822 | "addUceRegistrationOverrideShell"); |
| 10823 | final long identity = Binder.clearCallingIdentity(); |
| 10824 | try { |
| 10825 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10826 | new ArraySet<>(featureTags)); |
| 10827 | } catch (ImsException e) { |
| 10828 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10829 | } finally { |
| 10830 | Binder.restoreCallingIdentity(identity); |
| 10831 | } |
| 10832 | } |
| 10833 | |
| 10834 | /** |
| 10835 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10836 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10837 | */ |
| 10838 | // Used for SHELL command only right now. |
| 10839 | @Override |
| 10840 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10841 | List<String> featureTags) { |
| 10842 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10843 | "removeUceRegistrationOverrideShell"); |
| 10844 | final long identity = Binder.clearCallingIdentity(); |
| 10845 | try { |
| 10846 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10847 | new ArraySet<>(featureTags)); |
| 10848 | } catch (ImsException e) { |
| 10849 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10850 | } finally { |
| 10851 | Binder.restoreCallingIdentity(identity); |
| 10852 | } |
| 10853 | } |
| 10854 | |
| 10855 | /** |
| 10856 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10857 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10858 | */ |
| 10859 | // Used for SHELL command only right now. |
| 10860 | @Override |
| 10861 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10862 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10863 | "clearUceRegistrationOverrideShell"); |
| 10864 | final long identity = Binder.clearCallingIdentity(); |
| 10865 | try { |
| 10866 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10867 | } catch (ImsException e) { |
| 10868 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10869 | } finally { |
| 10870 | Binder.restoreCallingIdentity(identity); |
| 10871 | } |
| 10872 | } |
| 10873 | |
| 10874 | /** |
| 10875 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10876 | */ |
| 10877 | // Used for SHELL command only right now. |
| 10878 | @Override |
| 10879 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10880 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10881 | "getLatestRcsContactUceCapabilityShell"); |
| 10882 | final long identity = Binder.clearCallingIdentity(); |
| 10883 | try { |
| 10884 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10885 | } catch (ImsException e) { |
| 10886 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10887 | } finally { |
| 10888 | Binder.restoreCallingIdentity(identity); |
| 10889 | } |
| 10890 | } |
| 10891 | |
| 10892 | /** |
| 10893 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10894 | * device does not have an active PUBLISH. |
| 10895 | */ |
| 10896 | // Used for SHELL command only right now. |
| 10897 | @Override |
| 10898 | public String getLastUcePidfXmlShell(int subId) { |
| 10899 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10900 | final long identity = Binder.clearCallingIdentity(); |
| 10901 | try { |
| 10902 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10903 | } catch (ImsException e) { |
| 10904 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10905 | } finally { |
| 10906 | Binder.restoreCallingIdentity(identity); |
| 10907 | } |
| 10908 | } |
| 10909 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10910 | /** |
| 10911 | * Remove UCE requests cannot be sent to the network status. |
| 10912 | */ |
| 10913 | // Used for SHELL command only right now. |
| 10914 | @Override |
| 10915 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10916 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10917 | final long identity = Binder.clearCallingIdentity(); |
| 10918 | try { |
| 10919 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10920 | } catch (ImsException e) { |
| 10921 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10922 | } finally { |
| 10923 | Binder.restoreCallingIdentity(identity); |
| 10924 | } |
| 10925 | } |
| 10926 | |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10927 | /** |
| 10928 | * Remove UCE requests cannot be sent to the network status. |
| 10929 | */ |
| 10930 | // Used for SHELL command only. |
| 10931 | @Override |
| 10932 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10933 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10934 | final long identity = Binder.clearCallingIdentity(); |
| 10935 | try { |
| 10936 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10937 | } catch (ImsException e) { |
| 10938 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10939 | } finally { |
| 10940 | Binder.restoreCallingIdentity(identity); |
| 10941 | } |
| 10942 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10943 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10944 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10945 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10946 | String callingPackage) { |
| 10947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10948 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10949 | |
| 10950 | final int callingUid = Binder.getCallingUid(); |
| 10951 | // Verify that tha callingPackage belongs to the calling UID |
| 10952 | mApp.getSystemService(AppOpsManager.class) |
| 10953 | .checkPackage(callingUid, callingPackage); |
| 10954 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10955 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10956 | |
| 10957 | final long identity = Binder.clearCallingIdentity(); |
| 10958 | try { |
| 10959 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10960 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10961 | |
| 10962 | if (result instanceof IllegalStateException) { |
| 10963 | throw (IllegalStateException) result; |
| 10964 | } |
| 10965 | } finally { |
| 10966 | Binder.restoreCallingIdentity(identity); |
| 10967 | } |
| 10968 | } |
| 10969 | |
| 10970 | @Override |
| 10971 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10972 | String callingPackage) { |
| 10973 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10974 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10975 | |
| 10976 | final int callingUid = Binder.getCallingUid(); |
| 10977 | // Verify that tha callingPackage belongs to the calling UID |
| 10978 | mApp.getSystemService(AppOpsManager.class) |
| 10979 | .checkPackage(callingUid, callingPackage); |
| 10980 | |
| 10981 | final long identity = Binder.clearCallingIdentity(); |
| 10982 | try { |
| 10983 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10984 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10985 | |
| 10986 | if (result instanceof IllegalStateException) { |
| 10987 | throw (IllegalStateException) result; |
| 10988 | } |
| 10989 | } finally { |
| 10990 | Binder.restoreCallingIdentity(identity); |
| 10991 | } |
| 10992 | } |
| 10993 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10994 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 10995 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10996 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10997 | // phone/system process do not have further restriction on request |
| 10998 | return; |
| 10999 | } |
| 11000 | |
| 11001 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11002 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11003 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11004 | context.enforceCallingOrSelfPermission( |
| 11005 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11006 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11007 | } |
| 11008 | |
| 11009 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11010 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11011 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11012 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11013 | || info.isEnabled()) { |
| 11014 | throw new IllegalArgumentException( |
| 11015 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11016 | } |
| 11017 | |
| 11018 | // Thresholds length for each RAN need in range. This has been validated in |
| 11019 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11020 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11021 | final int[] thresholds = info.getThresholds(); |
| 11022 | Objects.requireNonNull(thresholds); |
| 11023 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11024 | || thresholds.length |
| 11025 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11026 | throw new IllegalArgumentException( |
| 11027 | "thresholds length is out of range: " + thresholds.length); |
| 11028 | } |
| 11029 | } |
| 11030 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11031 | |
| 11032 | /** |
| 11033 | * Gets the current phone capability. |
| 11034 | * |
| 11035 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11036 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11037 | * It's used to evaluate possible phone config change, for example from single |
| 11038 | * SIM device to multi-SIM device. |
| 11039 | */ |
| 11040 | @Override |
| 11041 | public PhoneCapability getPhoneCapability() { |
| 11042 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11043 | final long identity = Binder.clearCallingIdentity(); |
| 11044 | try { |
| 11045 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11046 | } finally { |
| 11047 | Binder.restoreCallingIdentity(identity); |
| 11048 | } |
| 11049 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11050 | |
| 11051 | /** |
| 11052 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11053 | * required to be done shortly after the API is invoked. |
| 11054 | */ |
| 11055 | @Override |
| 11056 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11057 | public int prepareForUnattendedReboot() { |
| 11058 | enforceRebootPermission(); |
| 11059 | |
| 11060 | final long identity = Binder.clearCallingIdentity(); |
| 11061 | try { |
| 11062 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 11063 | } finally { |
| 11064 | Binder.restoreCallingIdentity(identity); |
| 11065 | } |
| 11066 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11067 | |
| 11068 | /** |
| 11069 | * Request to get the current slicing configuration including URSP rules and |
| 11070 | * NSSAIs (configured, allowed and rejected). |
| 11071 | * |
| 11072 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11073 | */ |
| 11074 | @Override |
| 11075 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11076 | TelephonyPermissions |
| 11077 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11078 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11079 | |
| 11080 | final long identity = Binder.clearCallingIdentity(); |
| 11081 | try { |
| 11082 | Phone phone = getDefaultPhone(); |
| 11083 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11084 | } finally { |
| 11085 | Binder.restoreCallingIdentity(identity); |
| 11086 | } |
| 11087 | } |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 11088 | |
| 11089 | /** |
| 11090 | * Register an IMS connection state callback |
| 11091 | */ |
| 11092 | @Override |
| 11093 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11094 | String callingPackage) { |
| 11095 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11096 | // ImsMmTelManager |
| 11097 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11098 | TelephonyPermissions |
| 11099 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11100 | mApp, subId, "registerImsStateCallback"); |
| 11101 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11102 | // ImsRcsManager or SipDelegateManager |
| 11103 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11104 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11105 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11106 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11107 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11108 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11109 | } |
| 11110 | |
| 11111 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11112 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11113 | "IMS not available on device."); |
| 11114 | } |
| 11115 | |
| 11116 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11117 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11118 | } |
| 11119 | |
| 11120 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11121 | if (controller == null) { |
| 11122 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11123 | "IMS not available on device."); |
| 11124 | } |
| 11125 | |
| 11126 | if (callingPackage == null) { |
| 11127 | callingPackage = getCurrentPackageName(); |
| 11128 | } |
| 11129 | |
| 11130 | final long token = Binder.clearCallingIdentity(); |
| 11131 | try { |
| 11132 | int slotId = getSlotIndexOrException(subId); |
| 11133 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
| 11134 | } catch (ImsException e) { |
| 11135 | throw new ServiceSpecificException(e.getCode()); |
| 11136 | } finally { |
| 11137 | Binder.restoreCallingIdentity(token); |
| 11138 | } |
| 11139 | } |
| 11140 | |
| 11141 | /** |
| 11142 | * Unregister an IMS connection state callback |
| 11143 | */ |
| 11144 | @Override |
| 11145 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11146 | final long token = Binder.clearCallingIdentity(); |
| 11147 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11148 | if (controller == null) { |
| 11149 | return; |
| 11150 | } |
| 11151 | try { |
| 11152 | controller.unregisterImsStateCallback(cb); |
| 11153 | } finally { |
| 11154 | Binder.restoreCallingIdentity(token); |
| 11155 | } |
| 11156 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11157 | |
| 11158 | /** |
| 11159 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11160 | * |
| 11161 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11162 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11163 | * SecurityException. |
| 11164 | * If there is current registered network this value will be same as the registered cell |
| 11165 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11166 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11167 | * it will be cleared and null will be returned. |
| 11168 | * |
| 11169 | */ |
| 11170 | @Override |
| 11171 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11172 | String callingFeatureId) { |
| 11173 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11174 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11175 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11176 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11177 | .setCallingPackage(callingPackage) |
| 11178 | .setCallingFeatureId(callingFeatureId) |
| 11179 | .setCallingPid(Binder.getCallingPid()) |
| 11180 | .setCallingUid(Binder.getCallingUid()) |
| 11181 | .setMethod("getLastKnownCellIdentity") |
| 11182 | .setLogAsInfo(true) |
| 11183 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11184 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11185 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11186 | .build()); |
| 11187 | |
| 11188 | boolean hasFinePermission = |
| 11189 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11190 | if (!hasFinePermission |
| 11191 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11192 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11193 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11194 | } |
| 11195 | |
| 11196 | final long identity = Binder.clearCallingIdentity(); |
| 11197 | try { |
| 11198 | Phone phone = getPhone(subId); |
| 11199 | if (phone == null) return null; |
| 11200 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11201 | if (sst == null) return null; |
| 11202 | return sst.getLastKnownCellIdentity(); |
| 11203 | } finally { |
| 11204 | Binder.restoreCallingIdentity(identity); |
| 11205 | } |
| 11206 | } |
jimsun | 38340bf | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11207 | |
| 11208 | /** |
| 11209 | * Sets the modem service class Name that Telephony will bind to. |
| 11210 | * |
| 11211 | * @param serviceName The class name of the modem service. |
| 11212 | * @return true if the operation is succeed, otherwise false. |
| 11213 | */ |
| 11214 | public boolean setModemService(String serviceName) { |
| 11215 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11216 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11217 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11218 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11219 | "setModemService"); |
| 11220 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11221 | } |
| 11222 | |
| 11223 | /** |
| 11224 | * Return the class name of the currently bounded modem service. |
| 11225 | * |
| 11226 | * @return the class name of the modem service. |
| 11227 | */ |
| 11228 | public String getModemService() { |
| 11229 | String result; |
| 11230 | Log.d(LOG_TAG, "getModemService"); |
| 11231 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11232 | TelephonyPermissions |
| 11233 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11234 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11235 | "getModemService"); |
| 11236 | result = mPhoneConfigurationManager.getModemService(); |
| 11237 | Log.d(LOG_TAG, "result = " + result); |
| 11238 | return result; |
| 11239 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11240 | } |