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; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 22 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 27 | 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] | 28 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 29 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 30 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 37 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 38 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 39 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.compat.annotation.ChangeId; |
| 41 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 42 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 43 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.content.Context; |
| 45 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.AsyncResult; |
| 51 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 52 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
| 54 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.IBinder; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 56 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.Looper; |
| 58 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 59 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 60 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 61 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 62 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 63 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 64 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 65 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 66 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 67 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 69 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 70 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 71 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 72 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 73 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 74 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 75 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 76 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 77 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 78 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 79 | import android.telephony.AccessNetworkConstants; |
| 80 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 81 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 82 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 84 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 85 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 86 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 87 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 88 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 89 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 90 | import android.telephony.CellIdentityCdma; |
| 91 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 93 | import android.telephony.CellInfoGsm; |
| 94 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 95 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 96 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 97 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 98 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 99 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 100 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 101 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 102 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 103 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 104 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 105 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 106 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 107 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 108 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 109 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 110 | import android.telephony.SignalStrengthUpdateRequest; |
| 111 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 112 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 113 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 114 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 115 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 116 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 118 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 119 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 120 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 121 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 122 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 123 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 124 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 125 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 126 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 127 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 128 | import android.telephony.gba.GbaAuthRequest; |
| 129 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 130 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 131 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 132 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 133 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 134 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 135 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 142 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 144 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 146 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 147 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 148 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 149 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 150 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 151 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 152 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 153 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 154 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 189 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 193 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 196 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 201 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 205 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.uicc.IccIoResult; |
| 208 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 214 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 216 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 217 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 219 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 220 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 221 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 222 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 223 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 224 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 225 | import com.android.phone.slice.SlicePurchaseController; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 226 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 227 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 228 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 229 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 230 | import com.android.services.telephony.TelecomAccountRegistry; |
| 231 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 232 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 233 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 234 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 235 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 236 | import java.io.IOException; |
| 237 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 238 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 239 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 240 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 241 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 242 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 243 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 244 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 245 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 246 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 247 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 248 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 249 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 250 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 251 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 252 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 253 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 254 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * Implementation of the ITelephony interface. |
| 258 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 259 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 260 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 261 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 262 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 263 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 264 | |
| 265 | // Message codes used with mMainThreadHandler |
| 266 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 267 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 268 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 269 | private static final int CMD_OPEN_CHANNEL = 9; |
| 270 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 271 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 272 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 273 | private static final int CMD_NV_READ_ITEM = 13; |
| 274 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 275 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 276 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 277 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 278 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 279 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 280 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 281 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 282 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 283 | private static final int CMD_SEND_ENVELOPE = 25; |
| 284 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 285 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 286 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 287 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 288 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 289 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 290 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 291 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 292 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 293 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 294 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 295 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 296 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 297 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 298 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 299 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 300 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 301 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 302 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 303 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 304 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 305 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 306 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 307 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 308 | private static final int CMD_SWITCH_SLOTS = 50; |
| 309 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 310 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 311 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 312 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 313 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 314 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 315 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 316 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 317 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 318 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 319 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 320 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 321 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 322 | private static final int CMD_MODEM_REBOOT = 64; |
| 323 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 324 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 325 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 326 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 327 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 329 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 330 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 331 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 332 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 333 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 334 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 335 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 336 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 337 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 338 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 339 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 340 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 341 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 342 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 343 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 344 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 345 | private static final int CMD_GET_CALL_WAITING = 87; |
| 346 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 347 | private static final int CMD_SET_CALL_WAITING = 89; |
| 348 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 349 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 350 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 351 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 352 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 353 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 354 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 355 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 356 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 357 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 358 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 359 | private static final int CMD_SET_SIM_POWER = 101; |
| 360 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 361 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 362 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 363 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 364 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 365 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 366 | 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] | 367 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 368 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 369 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 370 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 371 | private static final int CMD_ENABLE_VONR = 113; |
| 372 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 373 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 374 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 375 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 376 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 378 | // Parameters of select command. |
| 379 | private static final int SELECT_COMMAND = 0xA4; |
| 380 | private static final int SELECT_P1 = 0x04; |
| 381 | private static final int SELECT_P2 = 0; |
| 382 | private static final int SELECT_P3 = 0x10; |
| 383 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 384 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 385 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 386 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | /** The singleton instance. */ |
| 388 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 389 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 391 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 392 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 393 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 394 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 395 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 396 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 397 | private MainThreadHandler mMainThreadHandler; |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 398 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 399 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 400 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 401 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 402 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 403 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 404 | /** User Activity */ |
| 405 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 406 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 407 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 408 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 409 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 410 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 411 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 412 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 413 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 414 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 415 | // String to store multi SIM allowed |
| 416 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 417 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 418 | // The AID of ISD-R. |
| 419 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 420 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 421 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 422 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 423 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 424 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 425 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 426 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 427 | 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] | 428 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 429 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 430 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 431 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 432 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 433 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 434 | */ |
| 435 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 436 | "reset_network_erase_modem_config_enabled"; |
| 437 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 438 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 439 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 440 | /** |
| 441 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 442 | * one ICCID active at the same time. |
| 443 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 444 | * |
| 445 | * @hide |
| 446 | */ |
| 447 | @ChangeId |
| 448 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 449 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 450 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 451 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 452 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 453 | * operation fails. |
| 454 | */ |
| 455 | @ChangeId |
| 456 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 457 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 458 | |
| 459 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 460 | * A request object to use for transmitting data to an ICC. |
| 461 | */ |
| 462 | private static final class IccAPDUArgument { |
| 463 | public int channel, cla, command, p1, p2, p3; |
| 464 | public String data; |
| 465 | |
| 466 | public IccAPDUArgument(int channel, int cla, int command, |
| 467 | int p1, int p2, int p3, String data) { |
| 468 | this.channel = channel; |
| 469 | this.cla = cla; |
| 470 | this.command = command; |
| 471 | this.p1 = p1; |
| 472 | this.p2 = p2; |
| 473 | this.p3 = p3; |
| 474 | this.data = data; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 479 | * A request object to use for transmitting data to an ICC. |
| 480 | */ |
| 481 | private static final class ManualNetworkSelectionArgument { |
| 482 | public OperatorInfo operatorInfo; |
| 483 | public boolean persistSelection; |
| 484 | |
| 485 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 486 | this.operatorInfo = operatorInfo; |
| 487 | this.persistSelection = persistSelection; |
| 488 | } |
| 489 | } |
| 490 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 491 | private static final class PurchasePremiumCapabilityArgument { |
| 492 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 493 | public @NonNull IIntegerConsumer callback; |
| 494 | |
| 495 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame^] | 496 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 497 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 498 | this.callback = callback; |
| 499 | } |
| 500 | } |
| 501 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 502 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 503 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 504 | * request after sending. The main thread will notify the request when it is complete. |
| 505 | */ |
| 506 | private static final class MainThreadRequest { |
| 507 | /** The argument to use for the request */ |
| 508 | public Object argument; |
| 509 | /** The result of the request that is run on the main thread */ |
| 510 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 511 | // The subscriber id that this request applies to. Defaults to |
| 512 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 513 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 514 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 515 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 516 | public Phone phone; |
| 517 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 518 | public WorkSource workSource; |
| 519 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | public MainThreadRequest(Object argument) { |
| 521 | this.argument = argument; |
| 522 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 523 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 524 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 525 | this.argument = argument; |
| 526 | if (phone != null) { |
| 527 | this.phone = phone; |
| 528 | } |
| 529 | this.workSource = workSource; |
| 530 | } |
| 531 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 532 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 533 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 534 | if (subId != null) { |
| 535 | this.subId = subId; |
| 536 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 537 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 541 | private static final class IncomingThirdPartyCallArgs { |
| 542 | public final ComponentName component; |
| 543 | public final String callId; |
| 544 | public final String callerDisplayName; |
| 545 | |
| 546 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 547 | String callerDisplayName) { |
| 548 | this.component = component; |
| 549 | this.callId = callId; |
| 550 | this.callerDisplayName = callerDisplayName; |
| 551 | } |
| 552 | } |
| 553 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 554 | /** |
| 555 | * A handler that processes messages on the main thread in the phone process. Since many |
| 556 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 557 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 558 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 559 | * on, which will be notified when the operation completes and will contain the result of the |
| 560 | * request. |
| 561 | * |
| 562 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 563 | * note that request.result must be set to something non-null for the calling thread to |
| 564 | * unblock. |
| 565 | */ |
| 566 | private final class MainThreadHandler extends Handler { |
| 567 | @Override |
| 568 | public void handleMessage(Message msg) { |
| 569 | MainThreadRequest request; |
| 570 | Message onCompleted; |
| 571 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 572 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 574 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 575 | |
| 576 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | case CMD_HANDLE_USSD_REQUEST: { |
| 578 | request = (MainThreadRequest) msg.obj; |
| 579 | final Phone phone = getPhoneFromRequest(request); |
| 580 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 581 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 583 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | if (!isUssdApiAllowed(request.subId)) { |
| 585 | // Carrier does not support use of this API, return failure. |
| 586 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 587 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 588 | Bundle returnData = new Bundle(); |
| 589 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 590 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 591 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | request.result = true; |
| 593 | notifyRequester(request); |
| 594 | return; |
| 595 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 596 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | try { |
| 598 | request.result = phone != null |
| 599 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 600 | } catch (CallStateException cse) { |
| 601 | request.result = false; |
| 602 | } |
| 603 | // Wake up the requesting thread |
| 604 | notifyRequester(request); |
| 605 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 608 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 609 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 610 | final Phone phone = getPhoneFromRequest(request); |
| 611 | request.result = phone != null ? |
| 612 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 613 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 614 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 615 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 616 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 618 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 622 | uiccPort = getUiccPortFromRequest(request); |
| 623 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 625 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 627 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 629 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 630 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 631 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 632 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 633 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 635 | break; |
| 636 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | ar = (AsyncResult) msg.obj; |
| 639 | request = (MainThreadRequest) ar.userObj; |
| 640 | if (ar.exception == null && ar.result != null) { |
| 641 | request.result = ar.result; |
| 642 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 643 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | if (ar.result == null) { |
| 645 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 646 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | } else { |
| 650 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 651 | } |
| 652 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 653 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | break; |
| 655 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 657 | request = (MainThreadRequest) msg.obj; |
| 658 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 659 | uiccPort = getUiccPortFromRequest(request); |
| 660 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 662 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | } else { |
| 665 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 666 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 667 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 669 | iccArgument.p2, |
| 670 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | } |
| 672 | break; |
| 673 | |
| 674 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 675 | ar = (AsyncResult) msg.obj; |
| 676 | request = (MainThreadRequest) ar.userObj; |
| 677 | if (ar.exception == null && ar.result != null) { |
| 678 | request.result = ar.result; |
| 679 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 680 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | if (ar.result == null) { |
| 682 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 683 | } else if (ar.exception instanceof CommandException) { |
| 684 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 685 | ar.exception); |
| 686 | } else { |
| 687 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 688 | } |
| 689 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 690 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case CMD_EXCHANGE_SIM_IO: |
| 694 | request = (MainThreadRequest) msg.obj; |
| 695 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 696 | uiccPort = getUiccPortFromRequest(request); |
| 697 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 698 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 699 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | } else { |
| 702 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 703 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 704 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 705 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 706 | iccArgument.data, onCompleted); |
| 707 | } |
| 708 | break; |
| 709 | |
| 710 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 711 | ar = (AsyncResult) msg.obj; |
| 712 | request = (MainThreadRequest) ar.userObj; |
| 713 | if (ar.exception == null && ar.result != null) { |
| 714 | request.result = ar.result; |
| 715 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 716 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 719 | break; |
| 720 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 721 | case CMD_SEND_ENVELOPE: |
| 722 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 723 | uiccPort = getUiccPortFromRequest(request); |
| 724 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 725 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 726 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 727 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 728 | } else { |
| 729 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 730 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 731 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 732 | break; |
| 733 | |
| 734 | case EVENT_SEND_ENVELOPE_DONE: |
| 735 | ar = (AsyncResult) msg.obj; |
| 736 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 737 | if (ar.exception == null && ar.result != null) { |
| 738 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 739 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 740 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 741 | if (ar.result == null) { |
| 742 | loge("sendEnvelopeWithStatus: Empty response"); |
| 743 | } else if (ar.exception instanceof CommandException) { |
| 744 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 745 | ar.exception); |
| 746 | } else { |
| 747 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 748 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 749 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 750 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 751 | break; |
| 752 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | case CMD_OPEN_CHANNEL: |
| 754 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 755 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 756 | IccLogicalChannelRequest openChannelRequest = |
| 757 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 758 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 759 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 760 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 761 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 763 | } else { |
| 764 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 765 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 766 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 767 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case EVENT_OPEN_CHANNEL_DONE: |
| 771 | ar = (AsyncResult) msg.obj; |
| 772 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 773 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 774 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 775 | int[] result = (int[]) ar.result; |
| 776 | int channelId = result[0]; |
| 777 | byte[] selectResponse = null; |
| 778 | if (result.length > 1) { |
| 779 | selectResponse = new byte[result.length - 1]; |
| 780 | for (int i = 1; i < result.length; ++i) { |
| 781 | selectResponse[i - 1] = (byte) result[i]; |
| 782 | } |
| 783 | } |
| 784 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 785 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 786 | |
| 787 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 788 | if (uiccPort == null) { |
| 789 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 790 | } else { |
| 791 | IccLogicalChannelRequest channelRequest = |
| 792 | (IccLogicalChannelRequest) request.argument; |
| 793 | channelRequest.channel = channelId; |
| 794 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 795 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 796 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 797 | if (ar.result == null) { |
| 798 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 800 | if (ar.exception != null) { |
| 801 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 802 | } |
| 803 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 804 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 805 | if (ar.exception instanceof CommandException) { |
| 806 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 807 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 808 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 809 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 810 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 811 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 815 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 816 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 817 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 818 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 819 | break; |
| 820 | |
| 821 | case CMD_CLOSE_CHANNEL: |
| 822 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 823 | uiccPort = getUiccPortFromRequest(request); |
| 824 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 825 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 826 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 827 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 828 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 829 | } else { |
| 830 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 831 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 832 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null) { |
| 839 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 840 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 841 | if (uiccPort == null) { |
| 842 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 843 | } else { |
| 844 | final int channelId = (Integer) request.argument; |
| 845 | uiccPort.onLogicalChannelClosed(channelId); |
| 846 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 847 | } else { |
| 848 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 849 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 850 | if (ar.exception instanceof CommandException) { |
| 851 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 852 | CommandException.Error error = |
| 853 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 854 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 855 | // should only throw exceptions from the binder threads. |
| 856 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 857 | "iccCloseLogicalChannel: invalid argument "); |
| 858 | } |
| 859 | } else { |
| 860 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 861 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 862 | request.result = (exception != null) ? exception : |
| 863 | new IllegalStateException( |
| 864 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 865 | } |
| 866 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | case CMD_NV_READ_ITEM: |
| 870 | request = (MainThreadRequest) msg.obj; |
| 871 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 872 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 873 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 874 | break; |
| 875 | |
| 876 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 877 | ar = (AsyncResult) msg.obj; |
| 878 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 879 | if (ar.exception == null && ar.result != null) { |
| 880 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 881 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 882 | request.result = ""; |
| 883 | if (ar.result == null) { |
| 884 | loge("nvReadItem: Empty response"); |
| 885 | } else if (ar.exception instanceof CommandException) { |
| 886 | loge("nvReadItem: CommandException: " + |
| 887 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 888 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 889 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 890 | } |
| 891 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 892 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 893 | break; |
| 894 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 895 | case CMD_NV_WRITE_ITEM: |
| 896 | request = (MainThreadRequest) msg.obj; |
| 897 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 898 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 899 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 900 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 901 | break; |
| 902 | |
| 903 | case EVENT_NV_WRITE_ITEM_DONE: |
| 904 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 905 | break; |
| 906 | |
| 907 | case CMD_NV_WRITE_CDMA_PRL: |
| 908 | request = (MainThreadRequest) msg.obj; |
| 909 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 910 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 914 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 915 | break; |
| 916 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 917 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 918 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 919 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 920 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 923 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 924 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 925 | break; |
| 926 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 927 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 930 | request); |
| 931 | Phone phone = getPhoneFromRequest(request); |
| 932 | if (phone != null) { |
| 933 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 934 | } else { |
| 935 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 936 | request.result = false; |
| 937 | notifyRequester(request); |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 943 | ar = (AsyncResult) msg.obj; |
| 944 | request = (MainThreadRequest) ar.userObj; |
| 945 | if (ar.exception == null && ar.result != null) { |
| 946 | request.result = ar.result; |
| 947 | } else { |
| 948 | // request.result must be set to something non-null |
| 949 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 950 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 951 | request.result = ar.result; |
| 952 | } else { |
| 953 | request.result = false; |
| 954 | } |
| 955 | if (ar.result == null) { |
| 956 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 957 | } else if (ar.exception instanceof CommandException) { |
| 958 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 959 | + ar.exception); |
| 960 | } else { |
| 961 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 962 | } |
| 963 | } |
| 964 | notifyRequester(request); |
| 965 | break; |
| 966 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 967 | case CMD_IS_VONR_ENABLED: { |
| 968 | request = (MainThreadRequest) msg.obj; |
| 969 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 970 | request); |
| 971 | Phone phone = getPhoneFromRequest(request); |
| 972 | if (phone != null) { |
| 973 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 974 | } else { |
| 975 | loge("isVoNrEnabled: No phone object"); |
| 976 | request.result = false; |
| 977 | notifyRequester(request); |
| 978 | } |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | case EVENT_IS_VONR_ENABLED_DONE: |
| 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
| 985 | if (ar.exception == null && ar.result != null) { |
| 986 | request.result = ar.result; |
| 987 | } else { |
| 988 | // request.result must be set to something non-null |
| 989 | // for the calling thread to unblock |
| 990 | if (ar.result != null) { |
| 991 | request.result = ar.result; |
| 992 | } else { |
| 993 | request.result = false; |
| 994 | } |
| 995 | if (ar.result == null) { |
| 996 | loge("isVoNrEnabled: Empty response"); |
| 997 | } else if (ar.exception instanceof CommandException) { |
| 998 | loge("isVoNrEnabled: CommandException: " |
| 999 | + ar.exception); |
| 1000 | } else { |
| 1001 | loge("isVoNrEnabled: Unknown exception"); |
| 1002 | } |
| 1003 | } |
| 1004 | notifyRequester(request); |
| 1005 | break; |
| 1006 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1007 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1010 | Phone phone = getPhoneFromRequest(request); |
| 1011 | if (phone != null) { |
| 1012 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1013 | request.workSource); |
| 1014 | } else { |
| 1015 | loge("enableNrDualConnectivity: No phone object"); |
| 1016 | request.result = |
| 1017 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1018 | notifyRequester(request); |
| 1019 | } |
| 1020 | break; |
| 1021 | } |
| 1022 | |
| 1023 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1024 | ar = (AsyncResult) msg.obj; |
| 1025 | request = (MainThreadRequest) ar.userObj; |
| 1026 | if (ar.exception == null) { |
| 1027 | request.result = |
| 1028 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1029 | } else { |
| 1030 | request.result = |
| 1031 | TelephonyManager |
| 1032 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1033 | if (ar.exception instanceof CommandException) { |
| 1034 | CommandException.Error error = |
| 1035 | ((CommandException) (ar.exception)).getCommandError(); |
| 1036 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1037 | request.result = |
| 1038 | TelephonyManager |
| 1039 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1040 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1041 | request.result = |
| 1042 | TelephonyManager |
| 1043 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1044 | } |
| 1045 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1046 | + ar.exception); |
| 1047 | } else { |
| 1048 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1049 | } |
| 1050 | } |
| 1051 | notifyRequester(request); |
| 1052 | break; |
| 1053 | } |
| 1054 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1055 | case CMD_ENABLE_VONR: { |
| 1056 | request = (MainThreadRequest) msg.obj; |
| 1057 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1058 | Phone phone = getPhoneFromRequest(request); |
| 1059 | if (phone != null) { |
| 1060 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1061 | request.workSource); |
| 1062 | } else { |
| 1063 | loge("setVoNrEnabled: No phone object"); |
| 1064 | request.result = |
| 1065 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1066 | notifyRequester(request); |
| 1067 | } |
| 1068 | break; |
| 1069 | } |
| 1070 | |
| 1071 | case EVENT_ENABLE_VONR_DONE: { |
| 1072 | ar = (AsyncResult) msg.obj; |
| 1073 | request = (MainThreadRequest) ar.userObj; |
| 1074 | if (ar.exception == null) { |
| 1075 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1076 | } else { |
| 1077 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1078 | if (ar.exception instanceof CommandException) { |
| 1079 | CommandException.Error error = |
| 1080 | ((CommandException) (ar.exception)).getCommandError(); |
| 1081 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1082 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1083 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1084 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1085 | } else { |
| 1086 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1087 | } |
| 1088 | loge("setVoNrEnabled" + ": CommandException: " |
| 1089 | + ar.exception); |
| 1090 | } else { |
| 1091 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1092 | } |
| 1093 | } |
| 1094 | notifyRequester(request); |
| 1095 | break; |
| 1096 | } |
| 1097 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1098 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1099 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1100 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1101 | request); |
| 1102 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1103 | break; |
| 1104 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1105 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1106 | ar = (AsyncResult) msg.obj; |
| 1107 | request = (MainThreadRequest) ar.userObj; |
| 1108 | if (ar.exception == null && ar.result != null) { |
| 1109 | request.result = ar.result; // Integer |
| 1110 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1111 | // request.result must be set to something non-null |
| 1112 | // for the calling thread to unblock |
| 1113 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1114 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1115 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1116 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1117 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1118 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1120 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1121 | } |
| 1122 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1123 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1124 | break; |
| 1125 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1126 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1127 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1128 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1129 | request); |
| 1130 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1131 | (Pair<Integer, Long>) request.argument; |
| 1132 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1133 | reasonWithNetworkTypes.first, |
| 1134 | reasonWithNetworkTypes.second, |
| 1135 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1136 | break; |
| 1137 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1138 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1139 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1140 | break; |
| 1141 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1142 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1143 | request = (MainThreadRequest)msg.obj; |
| 1144 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1145 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1146 | break; |
| 1147 | |
| 1148 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1149 | ar = (AsyncResult)msg.obj; |
| 1150 | request = (MainThreadRequest)ar.userObj; |
| 1151 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1152 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1153 | break; |
| 1154 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1155 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1158 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1159 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1160 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1161 | break; |
| 1162 | |
| 1163 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1164 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1165 | break; |
| 1166 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1167 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1168 | request = (MainThreadRequest) msg.obj; |
| 1169 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1170 | request); |
| 1171 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1172 | break; |
| 1173 | |
| 1174 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1175 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1176 | break; |
| 1177 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1178 | case CMD_PERFORM_NETWORK_SCAN: |
| 1179 | request = (MainThreadRequest) msg.obj; |
| 1180 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1181 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1182 | break; |
| 1183 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1185 | request = (MainThreadRequest) msg.obj; |
| 1186 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1188 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1189 | request.argument; |
| 1190 | int callForwardingReason = args.first; |
| 1191 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1193 | } |
| 1194 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1195 | ar = (AsyncResult) msg.obj; |
| 1196 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1197 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1198 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1199 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1200 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1203 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1204 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1205 | // any service for voice call. |
| 1206 | if ((callForwardInfo.serviceClass |
| 1207 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1208 | callForwardingInfo = new CallForwardingInfo( |
| 1209 | callForwardInfo.status |
| 1210 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | callForwardInfo.reason, |
| 1212 | callForwardInfo.number, |
| 1213 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | break; |
| 1215 | } |
| 1216 | } |
| 1217 | // Didn't find a call forward info for voice call. |
| 1218 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1220 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1221 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1222 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1223 | } else { |
| 1224 | if (ar.result == null) { |
| 1225 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1226 | } |
| 1227 | if (ar.exception != null) { |
| 1228 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1229 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1230 | int errorCode = TelephonyManager |
| 1231 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | if (ar.exception instanceof CommandException) { |
| 1233 | CommandException.Error error = |
| 1234 | ((CommandException) (ar.exception)).getCommandError(); |
| 1235 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1236 | errorCode = TelephonyManager |
| 1237 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | errorCode = TelephonyManager |
| 1240 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1241 | } |
| 1242 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1243 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | request = (MainThreadRequest) msg.obj; |
| 1250 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1254 | request.argument).first; |
| 1255 | request.phone.setCallForwardingOption( |
| 1256 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1257 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | callForwardingInfoToSet.getReason(), |
| 1260 | callForwardingInfoToSet.getNumber(), |
| 1261 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1262 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | Consumer<Integer> callback = |
| 1269 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1270 | request.argument).second; |
| 1271 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1273 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1274 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | if (ar.exception instanceof CommandException) { |
| 1276 | CommandException.Error error = |
| 1277 | ((CommandException) (ar.exception)).getCommandError(); |
| 1278 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1279 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1280 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1282 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1283 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | callback.accept(errorCode); |
| 1287 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1288 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1296 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1297 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | ar = (AsyncResult) msg.obj; |
| 1302 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1304 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1306 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | // Service Class is a bit mask per 3gpp 27.007. |
| 1308 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1309 | if (callForwardResults.length > 1 |
| 1310 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1312 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1314 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1316 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | } |
| 1318 | } else { |
| 1319 | if (ar.result == null) { |
| 1320 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1321 | } |
| 1322 | if (ar.exception != null) { |
| 1323 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1324 | } |
| 1325 | if (ar.exception instanceof CommandException) { |
| 1326 | CommandException.Error error = |
| 1327 | ((CommandException) (ar.exception)).getCommandError(); |
| 1328 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1329 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1331 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1332 | callWaitingStatus = |
| 1333 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1337 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | request = (MainThreadRequest) msg.obj; |
| 1343 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1345 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | ar = (AsyncResult) msg.obj; |
| 1351 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1353 | Consumer<Integer> callback = |
| 1354 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1355 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | if (ar.exception instanceof CommandException) { |
| 1358 | CommandException.Error error = |
| 1359 | ((CommandException) (ar.exception)).getCommandError(); |
| 1360 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1361 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1362 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1363 | callback.accept( |
| 1364 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | } else { |
| 1366 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1367 | } |
| 1368 | } else { |
| 1369 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1370 | } |
| 1371 | } else { |
| 1372 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1373 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1375 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1376 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1377 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1378 | ar = (AsyncResult) msg.obj; |
| 1379 | request = (MainThreadRequest) ar.userObj; |
| 1380 | CellNetworkScanResult cellScanResult; |
| 1381 | if (ar.exception == null && ar.result != null) { |
| 1382 | cellScanResult = new CellNetworkScanResult( |
| 1383 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1384 | (List<OperatorInfo>) ar.result); |
| 1385 | } else { |
| 1386 | if (ar.result == null) { |
| 1387 | loge("getCellNetworkScanResults: Empty response"); |
| 1388 | } |
| 1389 | if (ar.exception != null) { |
| 1390 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1391 | } |
| 1392 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1393 | if (ar.exception instanceof CommandException) { |
| 1394 | CommandException.Error error = |
| 1395 | ((CommandException) (ar.exception)).getCommandError(); |
| 1396 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1397 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1398 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1399 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1400 | } |
| 1401 | } |
| 1402 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1403 | } |
| 1404 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1405 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
| 1408 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1409 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1410 | ManualNetworkSelectionArgument selArg = |
| 1411 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1412 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1413 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1414 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1415 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | |
| 1418 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | if (ar.exception == null) { |
| 1422 | request.result = true; |
| 1423 | } else { |
| 1424 | request.result = false; |
| 1425 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1426 | } |
| 1427 | notifyRequester(request); |
| 1428 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1429 | break; |
| 1430 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1431 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1432 | request = (MainThreadRequest) msg.obj; |
| 1433 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1434 | if (defaultPhone != null) { |
| 1435 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1436 | } else { |
| 1437 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1438 | Bundle bundle = new Bundle(); |
| 1439 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1440 | new ModemActivityInfo(0, 0, 0, |
| 1441 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1442 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1443 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1444 | break; |
| 1445 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1446 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1449 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1450 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1451 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1452 | if (mLastModemActivityInfo == null) { |
| 1453 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1454 | mLastModemActivitySpecificInfo[0] = |
| 1455 | new ActivityStatsTechSpecificInfo( |
| 1456 | 0, |
| 1457 | 0, |
| 1458 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1459 | 0); |
| 1460 | mLastModemActivityInfo = |
| 1461 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1462 | } |
| 1463 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1464 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | // Update the last modem activity info and the result of the request. |
| 1466 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1467 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1468 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1469 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1470 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1471 | // We don't want to return mLastModemActivityInfo which is updated |
| 1472 | // inside mergeModemActivityInfo() |
| 1473 | ret = new ModemActivityInfo( |
| 1474 | mLastModemActivityInfo.getTimestampMillis(), |
| 1475 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1476 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1477 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1478 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1479 | } else { |
| 1480 | if (ar.result == null) { |
| 1481 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1482 | error = TelephonyManager.ModemActivityInfoException |
| 1483 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1484 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1485 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1486 | error = TelephonyManager.ModemActivityInfoException |
| 1487 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1488 | } else { |
| 1489 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1490 | error = TelephonyManager.ModemActivityInfoException |
| 1491 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1492 | } |
| 1493 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1494 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1495 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1496 | bundle.putParcelable( |
| 1497 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1498 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1499 | } else { |
| 1500 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1501 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1502 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1503 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1504 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1505 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1507 | case CMD_SET_ALLOWED_CARRIERS: |
| 1508 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1509 | CarrierRestrictionRules argument = |
| 1510 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1511 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1512 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1513 | break; |
| 1514 | |
| 1515 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1516 | ar = (AsyncResult) msg.obj; |
| 1517 | request = (MainThreadRequest) ar.userObj; |
| 1518 | if (ar.exception == null && ar.result != null) { |
| 1519 | request.result = ar.result; |
| 1520 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1521 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1522 | if (ar.exception instanceof CommandException) { |
| 1523 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1524 | CommandException.Error error = |
| 1525 | ((CommandException) (ar.exception)).getCommandError(); |
| 1526 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1527 | request.result = |
| 1528 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1529 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1530 | } else { |
| 1531 | loge("setAllowedCarriers: Unknown exception"); |
| 1532 | } |
| 1533 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1534 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1535 | break; |
| 1536 | |
| 1537 | case CMD_GET_ALLOWED_CARRIERS: |
| 1538 | request = (MainThreadRequest) msg.obj; |
| 1539 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1540 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1541 | break; |
| 1542 | |
| 1543 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1544 | ar = (AsyncResult) msg.obj; |
| 1545 | request = (MainThreadRequest) ar.userObj; |
| 1546 | if (ar.exception == null && ar.result != null) { |
| 1547 | request.result = ar.result; |
| 1548 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1549 | request.result = new IllegalStateException( |
| 1550 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1551 | if (ar.result == null) { |
| 1552 | loge("getAllowedCarriers: Empty response"); |
| 1553 | } else if (ar.exception instanceof CommandException) { |
| 1554 | loge("getAllowedCarriers: CommandException: " + |
| 1555 | ar.exception); |
| 1556 | } else { |
| 1557 | loge("getAllowedCarriers: Unknown exception"); |
| 1558 | } |
| 1559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1560 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1561 | break; |
| 1562 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1563 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1564 | ar = (AsyncResult) msg.obj; |
| 1565 | request = (MainThreadRequest) ar.userObj; |
| 1566 | if (ar.exception == null && ar.result != null) { |
| 1567 | request.result = ar.result; |
| 1568 | } else { |
| 1569 | request.result = new IllegalArgumentException( |
| 1570 | "Failed to retrieve Forbidden Plmns"); |
| 1571 | if (ar.result == null) { |
| 1572 | loge("getForbiddenPlmns: Empty response"); |
| 1573 | } else { |
| 1574 | loge("getForbiddenPlmns: Unknown exception"); |
| 1575 | } |
| 1576 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1577 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1578 | break; |
| 1579 | |
| 1580 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1581 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1582 | uiccPort = getUiccPortFromRequest(request); |
| 1583 | if (uiccPort == null) { |
| 1584 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1585 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1586 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1587 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1591 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1592 | if (uiccApp == null) { |
| 1593 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1594 | + appType); |
| 1595 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1596 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1597 | break; |
| 1598 | } else { |
| 1599 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1600 | + " specified type -- " + appType); |
| 1601 | } |
| 1602 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1603 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1604 | onCompleted); |
| 1605 | break; |
| 1606 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1607 | case CMD_SWITCH_SLOTS: |
| 1608 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1609 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1610 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1611 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | |
| 1614 | case EVENT_SWITCH_SLOTS_DONE: |
| 1615 | ar = (AsyncResult) msg.obj; |
| 1616 | request = (MainThreadRequest) ar.userObj; |
| 1617 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1618 | notifyRequester(request); |
| 1619 | break; |
| 1620 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1621 | request = (MainThreadRequest) msg.obj; |
| 1622 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1623 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1624 | break; |
| 1625 | |
| 1626 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1627 | ar = (AsyncResult) msg.obj; |
| 1628 | request = (MainThreadRequest) ar.userObj; |
| 1629 | if (ar.exception != null) { |
| 1630 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1631 | } else { |
| 1632 | int mode = ((int[]) ar.result)[0]; |
| 1633 | if (mode == 0) { |
| 1634 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1635 | } else { |
| 1636 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1637 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1638 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1639 | notifyRequester(request); |
| 1640 | break; |
| 1641 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1642 | request = (MainThreadRequest) msg.obj; |
| 1643 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1644 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1645 | break; |
| 1646 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1647 | ar = (AsyncResult) msg.obj; |
| 1648 | request = (MainThreadRequest) ar.userObj; |
| 1649 | if (ar.exception != null) { |
| 1650 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1651 | } else { |
| 1652 | request.result = ((int[]) ar.result)[0]; |
| 1653 | } |
| 1654 | notifyRequester(request); |
| 1655 | break; |
| 1656 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1659 | int mode = (int) request.argument; |
| 1660 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1661 | break; |
| 1662 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1663 | ar = (AsyncResult) msg.obj; |
| 1664 | request = (MainThreadRequest) ar.userObj; |
| 1665 | request.result = ar.exception == null; |
| 1666 | notifyRequester(request); |
| 1667 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1668 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1669 | request = (MainThreadRequest) msg.obj; |
| 1670 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1671 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1672 | break; |
| 1673 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1674 | ar = (AsyncResult) msg.obj; |
| 1675 | request = (MainThreadRequest) ar.userObj; |
| 1676 | if (ar.exception != null) { |
| 1677 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1678 | } else { |
| 1679 | request.result = ((int[]) ar.result)[0]; |
| 1680 | } |
| 1681 | notifyRequester(request); |
| 1682 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1683 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1686 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1687 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1688 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1689 | break; |
| 1690 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1691 | ar = (AsyncResult) msg.obj; |
| 1692 | request = (MainThreadRequest) ar.userObj; |
| 1693 | request.result = ar.exception == null; |
| 1694 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1695 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1696 | case CMD_GET_ALL_CELL_INFO: |
| 1697 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1698 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1699 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1700 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1701 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1702 | ar = (AsyncResult) msg.obj; |
| 1703 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1704 | // If a timeout occurs, the response will be null |
| 1705 | request.result = (ar.exception == null && ar.result != null) |
| 1706 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1707 | synchronized (request) { |
| 1708 | request.notifyAll(); |
| 1709 | } |
| 1710 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1711 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1712 | request = (MainThreadRequest) msg.obj; |
| 1713 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1714 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1715 | break; |
| 1716 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1717 | ar = (AsyncResult) msg.obj; |
| 1718 | request = (MainThreadRequest) ar.userObj; |
| 1719 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1720 | try { |
| 1721 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1722 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1723 | cb.onError( |
| 1724 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1725 | ar.exception.getClass().getName(), |
| 1726 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1727 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1728 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1729 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1730 | } else { |
| 1731 | // use the result as returned |
| 1732 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1733 | } |
| 1734 | } catch (RemoteException re) { |
| 1735 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1736 | } |
| 1737 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1738 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1739 | request = (MainThreadRequest) msg.obj; |
| 1740 | WorkSource ws = (WorkSource) request.argument; |
| 1741 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1742 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1743 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1744 | } |
| 1745 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1746 | ar = (AsyncResult) msg.obj; |
| 1747 | request = (MainThreadRequest) ar.userObj; |
| 1748 | if (ar.exception == null) { |
| 1749 | request.result = ar.result; |
| 1750 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1751 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1752 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1753 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | synchronized (request) { |
| 1757 | request.notifyAll(); |
| 1758 | } |
| 1759 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1760 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1761 | case CMD_MODEM_REBOOT: |
| 1762 | request = (MainThreadRequest) msg.obj; |
| 1763 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1764 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1765 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1766 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1767 | handleNullReturnEvent(msg, "rebootModem"); |
| 1768 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1769 | case CMD_REQUEST_ENABLE_MODEM: |
| 1770 | request = (MainThreadRequest) msg.obj; |
| 1771 | boolean enable = (boolean) request.argument; |
| 1772 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1773 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1774 | PhoneConfigurationManager.getInstance() |
| 1775 | .enablePhone(request.phone, enable, onCompleted); |
| 1776 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1777 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1778 | ar = (AsyncResult) msg.obj; |
| 1779 | request = (MainThreadRequest) ar.userObj; |
| 1780 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1781 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1782 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1783 | if ((boolean) request.result) { |
| 1784 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1785 | updateModemStateMetrics(); |
| 1786 | } else { |
| 1787 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1788 | + ar.exception); |
| 1789 | } |
| 1790 | notifyRequester(request); |
| 1791 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1792 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1793 | case CMD_GET_MODEM_STATUS: |
| 1794 | request = (MainThreadRequest) msg.obj; |
| 1795 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1796 | PhoneConfigurationManager.getInstance() |
| 1797 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1798 | break; |
| 1799 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1800 | ar = (AsyncResult) msg.obj; |
| 1801 | request = (MainThreadRequest) ar.userObj; |
| 1802 | int id = request.phone.getPhoneId(); |
| 1803 | if (ar.exception == null && ar.result != null) { |
| 1804 | request.result = ar.result; |
| 1805 | //update the cache as modem status has changed |
| 1806 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1807 | (boolean) request.result); |
| 1808 | } else { |
| 1809 | // Return true if modem status cannot be retrieved. For most cases, |
| 1810 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1811 | // and disable modem are not supported. Modem is always on. |
| 1812 | // TODO: this should be fixed in R to support a third |
| 1813 | // status UNKNOWN b/131631629 |
| 1814 | request.result = true; |
| 1815 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1816 | + ar.exception); |
| 1817 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1818 | notifyRequester(request); |
| 1819 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1820 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1821 | request = (MainThreadRequest) msg.obj; |
| 1822 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1823 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1824 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1825 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1826 | break; |
| 1827 | } |
| 1828 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1829 | ar = (AsyncResult) msg.obj; |
| 1830 | request = (MainThreadRequest) ar.userObj; |
| 1831 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1832 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1833 | args.second.accept(ar.exception == null); |
| 1834 | notifyRequester(request); |
| 1835 | break; |
| 1836 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1837 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1838 | request = (MainThreadRequest) msg.obj; |
| 1839 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1840 | Phone phone = getPhoneFromRequest(request); |
| 1841 | if (phone != null) { |
| 1842 | phone.getSystemSelectionChannels(onCompleted); |
| 1843 | } else { |
| 1844 | loge("getSystemSelectionChannels: No phone object"); |
| 1845 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1846 | notifyRequester(request); |
| 1847 | } |
| 1848 | break; |
| 1849 | } |
| 1850 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1851 | ar = (AsyncResult) msg.obj; |
| 1852 | request = (MainThreadRequest) ar.userObj; |
| 1853 | if (ar.exception == null && ar.result != null) { |
| 1854 | request.result = ar.result; |
| 1855 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1856 | request.result = new IllegalStateException( |
| 1857 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1858 | if (ar.result == null) { |
| 1859 | loge("getSystemSelectionChannels: Empty response"); |
| 1860 | } else { |
| 1861 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1862 | } |
| 1863 | } |
| 1864 | notifyRequester(request); |
| 1865 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1866 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1867 | ar = (AsyncResult) msg.obj; |
| 1868 | request = (MainThreadRequest) ar.userObj; |
| 1869 | if (ar.exception == null && ar.result != null) { |
| 1870 | request.result = ar.result; |
| 1871 | } else { |
| 1872 | request.result = -1; |
| 1873 | loge("Failed to set Forbidden Plmns"); |
| 1874 | if (ar.result == null) { |
| 1875 | loge("setForbidenPlmns: Empty response"); |
| 1876 | } else if (ar.exception != null) { |
| 1877 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1878 | request.result = -1; |
| 1879 | } else { |
| 1880 | loge("setForbiddenPlmns: Unknown exception"); |
| 1881 | } |
| 1882 | } |
| 1883 | notifyRequester(request); |
| 1884 | break; |
| 1885 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1886 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1887 | uiccPort = getUiccPortFromRequest(request); |
| 1888 | if (uiccPort == null) { |
| 1889 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1890 | request.result = -1; |
| 1891 | notifyRequester(request); |
| 1892 | break; |
| 1893 | } |
| 1894 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1895 | (Pair<Integer, List<String>>) request.argument; |
| 1896 | appType = setFplmnsArgs.first; |
| 1897 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1898 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1899 | if (uiccApp == null) { |
| 1900 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1901 | request.result = -1; |
| 1902 | loge("Failed to get UICC App"); |
| 1903 | notifyRequester(request); |
| 1904 | } else { |
| 1905 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1906 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1907 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1908 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1909 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1910 | case CMD_ERASE_MODEM_CONFIG: |
| 1911 | request = (MainThreadRequest) msg.obj; |
| 1912 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1913 | defaultPhone.eraseModemConfig(onCompleted); |
| 1914 | break; |
| 1915 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1916 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1917 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1918 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1919 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1920 | request = (MainThreadRequest) msg.obj; |
| 1921 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1922 | notifyRequester(request); |
| 1923 | break; |
| 1924 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1925 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1926 | request = (MainThreadRequest) msg.obj; |
| 1927 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1928 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1929 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1930 | changed.first, changed.second, onCompleted); |
| 1931 | break; |
| 1932 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1933 | ar = (AsyncResult) msg.obj; |
| 1934 | request = (MainThreadRequest) ar.userObj; |
| 1935 | if (ar.exception == null) { |
| 1936 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1937 | // If the operation is successful, update the PIN storage |
| 1938 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1939 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1940 | UiccController.getInstance().getPinStorage() |
| 1941 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1942 | } else { |
| 1943 | request.result = msg.arg1; |
| 1944 | } |
| 1945 | notifyRequester(request); |
| 1946 | break; |
| 1947 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1948 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1949 | request = (MainThreadRequest) msg.obj; |
| 1950 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1951 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1952 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1953 | enabled.first, enabled.second, onCompleted); |
| 1954 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1955 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1956 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1957 | ar = (AsyncResult) msg.obj; |
| 1958 | request = (MainThreadRequest) ar.userObj; |
| 1959 | if (ar.exception == null) { |
| 1960 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1961 | // If the operation is successful, update the PIN storage |
| 1962 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1963 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1964 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1965 | UiccController.getInstance().getPinStorage() |
| 1966 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1967 | } else { |
| 1968 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1969 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1970 | } else { |
| 1971 | request.result = msg.arg1; |
| 1972 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1973 | |
| 1974 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1975 | notifyRequester(request); |
| 1976 | break; |
| 1977 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1978 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1979 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1980 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1981 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1982 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1983 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1984 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1985 | |
| 1986 | case CMD_SET_DATA_THROTTLING: { |
| 1987 | request = (MainThreadRequest) msg.obj; |
| 1988 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1989 | DataThrottlingRequest dataThrottlingRequest = |
| 1990 | (DataThrottlingRequest) request.argument; |
| 1991 | Phone phone = getPhoneFromRequest(request); |
| 1992 | if (phone != null) { |
| 1993 | phone.setDataThrottling(onCompleted, |
| 1994 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1995 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1996 | } else { |
| 1997 | loge("setDataThrottling: No phone object"); |
| 1998 | request.result = |
| 1999 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2000 | notifyRequester(request); |
| 2001 | } |
| 2002 | |
| 2003 | break; |
| 2004 | } |
| 2005 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2006 | ar = (AsyncResult) msg.obj; |
| 2007 | request = (MainThreadRequest) ar.userObj; |
| 2008 | |
| 2009 | if (ar.exception == null) { |
| 2010 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2011 | } else if (ar.exception instanceof CommandException) { |
| 2012 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2013 | CommandException.Error error = |
| 2014 | ((CommandException) (ar.exception)).getCommandError(); |
| 2015 | |
| 2016 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2017 | request.result = TelephonyManager |
| 2018 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2019 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2020 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2021 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2022 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2023 | } else { |
| 2024 | request.result = |
| 2025 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2026 | } |
| 2027 | } else { |
| 2028 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2029 | } |
| 2030 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2031 | notifyRequester(request); |
| 2032 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2033 | |
| 2034 | case CMD_SET_SIM_POWER: { |
| 2035 | request = (MainThreadRequest) msg.obj; |
| 2036 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2037 | request = (MainThreadRequest) msg.obj; |
| 2038 | int stateToSet = |
| 2039 | ((Pair<Integer, IIntegerConsumer>) |
| 2040 | request.argument).first; |
| 2041 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2042 | break; |
| 2043 | } |
| 2044 | case EVENT_SET_SIM_POWER_DONE: { |
| 2045 | ar = (AsyncResult) msg.obj; |
| 2046 | request = (MainThreadRequest) ar.userObj; |
| 2047 | IIntegerConsumer callback = |
| 2048 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2049 | if (ar.exception != null) { |
| 2050 | loge("setSimPower exception: " + ar.exception); |
| 2051 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2052 | .RESULT_ERROR_UNKNOWN; |
| 2053 | if (ar.exception instanceof CommandException) { |
| 2054 | CommandException.Error error = |
| 2055 | ((CommandException) (ar.exception)).getCommandError(); |
| 2056 | if (error == CommandException.Error.SIM_ERR) { |
| 2057 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2058 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2059 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2060 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2061 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2062 | } else { |
| 2063 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2064 | } |
| 2065 | } |
| 2066 | try { |
| 2067 | callback.accept(errorCode); |
| 2068 | } catch (RemoteException e) { |
| 2069 | // Ignore if the remote process is no longer available to call back. |
| 2070 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2071 | } |
| 2072 | } else { |
| 2073 | try { |
| 2074 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2075 | } catch (RemoteException e) { |
| 2076 | // Ignore if the remote process is no longer available to call back. |
| 2077 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2078 | } |
| 2079 | } |
| 2080 | break; |
| 2081 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2082 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2083 | request = (MainThreadRequest) msg.obj; |
| 2084 | |
| 2085 | final Phone phone = getPhoneFromRequest(request); |
| 2086 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2087 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2088 | notifyRequester(request); |
| 2089 | break; |
| 2090 | } |
| 2091 | |
| 2092 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2093 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2094 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2095 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2096 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2097 | request.subId, pair.first /*callingUid*/, |
| 2098 | pair.second /*request*/, onCompleted); |
| 2099 | break; |
| 2100 | } |
| 2101 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2102 | ar = (AsyncResult) msg.obj; |
| 2103 | request = (MainThreadRequest) ar.userObj; |
| 2104 | // request.result will be the exception of ar if present, true otherwise. |
| 2105 | // Be cautious not to leave result null which will wait() forever |
| 2106 | request.result = ar.exception != null ? ar.exception : true; |
| 2107 | notifyRequester(request); |
| 2108 | break; |
| 2109 | } |
| 2110 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2111 | request = (MainThreadRequest) msg.obj; |
| 2112 | |
| 2113 | Phone phone = getPhoneFromRequest(request); |
| 2114 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2115 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2116 | notifyRequester(request); |
| 2117 | break; |
| 2118 | } |
| 2119 | |
| 2120 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2121 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2122 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2123 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2124 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2125 | request.subId, pair.first /*callingUid*/, |
| 2126 | pair.second /*request*/, onCompleted); |
| 2127 | break; |
| 2128 | } |
| 2129 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2130 | ar = (AsyncResult) msg.obj; |
| 2131 | request = (MainThreadRequest) ar.userObj; |
| 2132 | request.result = ar.exception != null ? ar.exception : true; |
| 2133 | notifyRequester(request); |
| 2134 | break; |
| 2135 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2136 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2137 | case CMD_GET_SLICING_CONFIG: { |
| 2138 | request = (MainThreadRequest) msg.obj; |
| 2139 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2140 | request.phone.getSlicingConfig(onCompleted); |
| 2141 | break; |
| 2142 | } |
| 2143 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2144 | ar = (AsyncResult) msg.obj; |
| 2145 | request = (MainThreadRequest) ar.userObj; |
| 2146 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2147 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2148 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2149 | Bundle bundle = new Bundle(); |
| 2150 | int resultCode = 0; |
| 2151 | if (ar.exception != null) { |
| 2152 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2153 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2154 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2155 | } else if (ar.result == null) { |
| 2156 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2157 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2158 | } else { |
| 2159 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2160 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2161 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2165 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2166 | } |
| 2167 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2168 | result.send(resultCode, bundle); |
| 2169 | notifyRequester(request); |
| 2170 | break; |
| 2171 | } |
| 2172 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2173 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2174 | request = (MainThreadRequest) msg.obj; |
| 2175 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2176 | PurchasePremiumCapabilityArgument arg = |
| 2177 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2178 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame^] | 2179 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2180 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2181 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2182 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2183 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2184 | ar = (AsyncResult) msg.obj; |
| 2185 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2186 | PurchasePremiumCapabilityArgument arg = |
| 2187 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2188 | try { |
| 2189 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2190 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2191 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2192 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2193 | + ", result= " |
| 2194 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2195 | } catch (RemoteException e) { |
| 2196 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2197 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2198 | + " failed: " + e; |
| 2199 | if (DBG) log(logStr); |
| 2200 | AnomalyReporter.reportAnomaly( |
| 2201 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2202 | } |
| 2203 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2204 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2205 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2206 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2207 | request = (MainThreadRequest) msg.obj; |
| 2208 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2209 | UiccController.getInstance().getPinStorage() |
| 2210 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2211 | notifyRequester(request); |
| 2212 | break; |
| 2213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2214 | default: |
| 2215 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2216 | break; |
| 2217 | } |
| 2218 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2219 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2220 | private void notifyRequester(MainThreadRequest request) { |
| 2221 | synchronized (request) { |
| 2222 | request.notifyAll(); |
| 2223 | } |
| 2224 | } |
| 2225 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2226 | private void handleNullReturnEvent(Message msg, String command) { |
| 2227 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2228 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2229 | if (ar.exception == null) { |
| 2230 | request.result = true; |
| 2231 | } else { |
| 2232 | request.result = false; |
| 2233 | if (ar.exception instanceof CommandException) { |
| 2234 | loge(command + ": CommandException: " + ar.exception); |
| 2235 | } else { |
| 2236 | loge(command + ": Unknown exception"); |
| 2237 | } |
| 2238 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2239 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | /** |
| 2244 | * Posts the specified command to be executed on the main thread, |
| 2245 | * waits for the request to complete, and returns the result. |
| 2246 | * @see #sendRequestAsync |
| 2247 | */ |
| 2248 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2249 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2250 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * Posts the specified command to be executed on the main thread, |
| 2255 | * waits for the request to complete, and returns the result. |
| 2256 | * @see #sendRequestAsync |
| 2257 | */ |
| 2258 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2259 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2260 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * Posts the specified command to be executed on the main thread, |
| 2265 | * waits for the request to complete, and returns the result. |
| 2266 | * @see #sendRequestAsync |
| 2267 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2268 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2269 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * Posts the specified command to be executed on the main thread, |
| 2274 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2275 | * if not timeout or null otherwise. |
| 2276 | * @see #sendRequestAsync |
| 2277 | */ |
| 2278 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2279 | long timeoutInMs) { |
| 2280 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Posts the specified command to be executed on the main thread, |
| 2285 | * waits for the request to complete, and returns the result. |
| 2286 | * @see #sendRequestAsync |
| 2287 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2288 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2289 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /** |
| 2293 | * Posts the specified command to be executed on the main thread, |
| 2294 | * waits for the request to complete, and returns the result. |
| 2295 | * @see #sendRequestAsync |
| 2296 | */ |
| 2297 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2298 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2299 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2303 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2304 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2305 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2306 | * @see #sendRequestAsync |
| 2307 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2308 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2309 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2311 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2312 | } |
| 2313 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2314 | MainThreadRequest request = null; |
| 2315 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2316 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2317 | } else if (phone != null) { |
| 2318 | request = new MainThreadRequest(argument, phone, workSource); |
| 2319 | } else { |
| 2320 | request = new MainThreadRequest(argument, subId, workSource); |
| 2321 | } |
| 2322 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2324 | msg.sendToTarget(); |
| 2325 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2326 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2328 | if (timeoutInMs >= 0) { |
| 2329 | // Wait for at least timeoutInMs before returning null request result |
| 2330 | long now = SystemClock.elapsedRealtime(); |
| 2331 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2332 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2333 | try { |
| 2334 | request.wait(deadline - now); |
| 2335 | } catch (InterruptedException e) { |
| 2336 | // Do nothing, go back and check if request is completed or timeout |
| 2337 | } finally { |
| 2338 | now = SystemClock.elapsedRealtime(); |
| 2339 | } |
| 2340 | } |
| 2341 | } else { |
| 2342 | // Wait for the request to complete |
| 2343 | while (request.result == null) { |
| 2344 | try { |
| 2345 | request.wait(); |
| 2346 | } catch (InterruptedException e) { |
| 2347 | // Do nothing, go back and wait until the request is complete |
| 2348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2352 | if (request.result == null) { |
| 2353 | Log.wtf(LOG_TAG, |
| 2354 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2355 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | return request.result; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2361 | * Posts the specified command to be executed on the main thread, and |
| 2362 | * returns immediately. |
| 2363 | * @see #sendRequest |
| 2364 | */ |
| 2365 | private void sendRequestAsync(int command) { |
| 2366 | mMainThreadHandler.sendEmptyMessage(command); |
| 2367 | } |
| 2368 | |
| 2369 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2370 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2371 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2372 | */ |
| 2373 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2374 | sendRequestAsync(command, argument, null, null); |
| 2375 | } |
| 2376 | |
| 2377 | /** |
| 2378 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2379 | * @see {@link #sendRequest(int,Object)} |
| 2380 | */ |
| 2381 | private void sendRequestAsync( |
| 2382 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2383 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2384 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2385 | msg.sendToTarget(); |
| 2386 | } |
| 2387 | |
| 2388 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2390 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2391 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2392 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | synchronized (PhoneInterfaceManager.class) { |
| 2394 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2395 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | } else { |
| 2397 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2398 | } |
| 2399 | return sInstance; |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2404 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2407 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2408 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2410 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | mMainThreadHandler = new MainThreadHandler(); |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 2412 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2413 | mTelephonySharedPreferences = |
| 2414 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2415 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2416 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2417 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2418 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2419 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2420 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2421 | Executors.newSingleThreadExecutor(), mApp); |
| 2422 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | publish(); |
| 2424 | } |
| 2425 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2426 | @VisibleForTesting |
| 2427 | public SharedPreferences getSharedPreferences() { |
| 2428 | return mTelephonySharedPreferences; |
| 2429 | } |
| 2430 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2431 | /** |
| 2432 | * Get the default phone for this device. |
| 2433 | */ |
| 2434 | @VisibleForTesting |
| 2435 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2436 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2437 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2438 | } |
| 2439 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | private void publish() { |
| 2441 | if (DBG) log("publish: " + this); |
| 2442 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2443 | TelephonyFrameworkInitializer |
| 2444 | .getTelephonyServiceManager() |
| 2445 | .getTelephonyServiceRegisterer() |
| 2446 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2449 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2450 | if (request.phone != null) { |
| 2451 | return request.phone; |
| 2452 | } else { |
| 2453 | return getPhoneFromSubId(request.subId); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | private Phone getPhoneFromSubId(int subId) { |
| 2458 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2459 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2460 | } |
| 2461 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2462 | @Nullable |
| 2463 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2464 | Phone phone = getPhoneFromRequest(request); |
| 2465 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2466 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2469 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2470 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2471 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2472 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2473 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2474 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2475 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2476 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2477 | } |
| 2478 | |
| 2479 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2480 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2481 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2484 | private boolean isImsAvailableOnDevice() { |
| 2485 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2486 | if (pm == null) { |
| 2487 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2488 | // so do not throw error and allow. |
| 2489 | return true; |
| 2490 | } |
| 2491 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2492 | } |
| 2493 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2494 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2495 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2498 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | if (DBG) log("dial: " + number); |
| 2500 | // No permission check needed here: This is just a wrapper around the |
| 2501 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2502 | // the UI before it does anything. |
| 2503 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | final long identity = Binder.clearCallingIdentity(); |
| 2505 | try { |
| 2506 | String url = createTelUrl(number); |
| 2507 | if (url == null) { |
| 2508 | return; |
| 2509 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2512 | PhoneConstants.State state = mCM.getState(subId); |
| 2513 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2514 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2515 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2516 | mApp.startActivity(intent); |
| 2517 | } |
| 2518 | } finally { |
| 2519 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2524 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2527 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | if (DBG) log("call: " + number); |
| 2529 | |
| 2530 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2531 | // need to do a permission check since we're calling startActivity() |
| 2532 | // from the context of the phone app. |
| 2533 | enforceCallPermission(); |
| 2534 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2535 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2536 | != AppOpsManager.MODE_ALLOWED) { |
| 2537 | return; |
| 2538 | } |
| 2539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2540 | final long identity = Binder.clearCallingIdentity(); |
| 2541 | try { |
| 2542 | String url = createTelUrl(number); |
| 2543 | if (url == null) { |
| 2544 | return; |
| 2545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2547 | boolean isValid = false; |
| 2548 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2549 | if (slist != null) { |
| 2550 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2551 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2552 | isValid = true; |
| 2553 | break; |
| 2554 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2555 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | if (!isValid) { |
| 2558 | return; |
| 2559 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2561 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2562 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2563 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2564 | mApp.startActivity(intent); |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
| 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2570 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2571 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2572 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2573 | } |
| 2574 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2575 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2576 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2577 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2578 | } |
| 2579 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2580 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2585 | Phone phone = getPhone(subId); |
| 2586 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | checkSimPin.start(); |
| 2588 | return checkSimPin.unlockSim(null, pin); |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2594 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2596 | |
| 2597 | final long identity = Binder.clearCallingIdentity(); |
| 2598 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2599 | Phone phone = getPhone(subId); |
| 2600 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | checkSimPuk.start(); |
| 2602 | return checkSimPuk.unlockSim(puk, pin); |
| 2603 | } finally { |
| 2604 | Binder.restoreCallingIdentity(identity); |
| 2605 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2609 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2610 | * a synchronous one. |
| 2611 | */ |
| 2612 | private static class UnlockSim extends Thread { |
| 2613 | |
| 2614 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2615 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | |
| 2617 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2618 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2619 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | |
| 2621 | // For replies from SimCard interface |
| 2622 | private Handler mHandler; |
| 2623 | |
| 2624 | // For async handler to identify request type |
| 2625 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2626 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2627 | UnlockSim(int phoneId, IccCard simCard) { |
| 2628 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | mSimCard = simCard; |
| 2630 | } |
| 2631 | |
| 2632 | @Override |
| 2633 | public void run() { |
| 2634 | Looper.prepare(); |
| 2635 | synchronized (UnlockSim.this) { |
| 2636 | mHandler = new Handler() { |
| 2637 | @Override |
| 2638 | public void handleMessage(Message msg) { |
| 2639 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2640 | switch (msg.what) { |
| 2641 | case SUPPLY_PIN_COMPLETE: |
| 2642 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2643 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2644 | mRetryCount = msg.arg1; |
| 2645 | if (ar.exception != null) { |
| 2646 | if (ar.exception instanceof CommandException && |
| 2647 | ((CommandException)(ar.exception)).getCommandError() |
| 2648 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2649 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2650 | } //When UiccCardApp dispose,handle message and return exception |
| 2651 | else if (ar.exception instanceof CommandException && |
| 2652 | ((CommandException) (ar.exception)).getCommandError() |
| 2653 | == CommandException.Error.ABORTED) { |
| 2654 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2655 | } else { |
| 2656 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2657 | } |
| 2658 | } else { |
| 2659 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | mDone = true; |
| 2662 | UnlockSim.this.notifyAll(); |
| 2663 | } |
| 2664 | break; |
| 2665 | } |
| 2666 | } |
| 2667 | }; |
| 2668 | UnlockSim.this.notifyAll(); |
| 2669 | } |
| 2670 | Looper.loop(); |
| 2671 | } |
| 2672 | |
| 2673 | /* |
| 2674 | * Use PIN or PUK to unlock SIM card |
| 2675 | * |
| 2676 | * If PUK is null, unlock SIM card with PIN |
| 2677 | * |
| 2678 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2679 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2680 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2681 | |
| 2682 | while (mHandler == null) { |
| 2683 | try { |
| 2684 | wait(); |
| 2685 | } catch (InterruptedException e) { |
| 2686 | Thread.currentThread().interrupt(); |
| 2687 | } |
| 2688 | } |
| 2689 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2690 | |
| 2691 | if (puk == null) { |
| 2692 | mSimCard.supplyPin(pin, callback); |
| 2693 | } else { |
| 2694 | mSimCard.supplyPuk(puk, pin, callback); |
| 2695 | } |
| 2696 | |
| 2697 | while (!mDone) { |
| 2698 | try { |
| 2699 | Log.d(LOG_TAG, "wait for done"); |
| 2700 | wait(); |
| 2701 | } catch (InterruptedException e) { |
| 2702 | // Restore the interrupted status |
| 2703 | Thread.currentThread().interrupt(); |
| 2704 | } |
| 2705 | } |
| 2706 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2707 | int[] resultArray = new int[2]; |
| 2708 | resultArray[0] = mResult; |
| 2709 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2710 | |
| 2711 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2712 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2715 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | } |
| 2717 | } |
| 2718 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2719 | /** |
| 2720 | * This method has been removed due to privacy and stability concerns. |
| 2721 | */ |
| 2722 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2724 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2725 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2728 | @Override |
| 2729 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2730 | mApp.getSystemService(AppOpsManager.class) |
| 2731 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2732 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2733 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2734 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2735 | // Callers targeting S have no business invoking this method. |
| 2736 | return; |
| 2737 | } |
| 2738 | |
| 2739 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2740 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2741 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2742 | .setCallingPackage(callingPackage) |
| 2743 | .setCallingFeatureId(null) |
| 2744 | .setCallingPid(Binder.getCallingPid()) |
| 2745 | .setCallingUid(Binder.getCallingUid()) |
| 2746 | .setMethod("updateServiceLocation") |
| 2747 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2748 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2749 | .build()); |
| 2750 | // Apps that lack location permission have no business calling this method; |
| 2751 | // however, because no permission was declared in the public API, denials must |
| 2752 | // all be "soft". |
| 2753 | switch (locationResult) { |
| 2754 | case DENIED_HARD: /* fall through */ |
| 2755 | case DENIED_SOFT: |
| 2756 | return; |
| 2757 | } |
| 2758 | |
| 2759 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | final long identity = Binder.clearCallingIdentity(); |
| 2761 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2762 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2764 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | } |
| 2766 | } finally { |
| 2767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2771 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2772 | @Override |
| 2773 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2774 | return isRadioOnWithFeature(callingPackage, null); |
| 2775 | } |
| 2776 | |
| 2777 | |
| 2778 | @Override |
| 2779 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2780 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2781 | callingFeatureId); |
| 2782 | } |
| 2783 | |
| 2784 | @Deprecated |
| 2785 | @Override |
| 2786 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2787 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2790 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2791 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2792 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2793 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2794 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2795 | return false; |
| 2796 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | |
| 2798 | final long identity = Binder.clearCallingIdentity(); |
| 2799 | try { |
| 2800 | return isRadioOnForSubscriber(subId); |
| 2801 | } finally { |
| 2802 | Binder.restoreCallingIdentity(identity); |
| 2803 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | final Phone phone = getPhone(subId); |
| 2810 | if (phone != null) { |
| 2811 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2812 | } else { |
| 2813 | return false; |
| 2814 | } |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2821 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2822 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2823 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2824 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | |
| 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
| 2829 | final Phone phone = getPhone(subId); |
| 2830 | if (phone != null) { |
| 2831 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2832 | } |
| 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2835 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2839 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2842 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2843 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2844 | |
| 2845 | final long identity = Binder.clearCallingIdentity(); |
| 2846 | try { |
| 2847 | final Phone phone = getPhone(subId); |
| 2848 | if (phone == null) { |
| 2849 | return false; |
| 2850 | } |
| 2851 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2852 | toggleRadioOnOffForSubscriber(subId); |
| 2853 | } |
| 2854 | return true; |
| 2855 | } finally { |
| 2856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2858 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2859 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2860 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2861 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2862 | /* |
| 2863 | * If any of the Radios are available, it will need to be |
| 2864 | * shutdown. So return true if any Radio is available. |
| 2865 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2866 | final long identity = Binder.clearCallingIdentity(); |
| 2867 | try { |
| 2868 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2869 | Phone phone = PhoneFactory.getPhone(i); |
| 2870 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2871 | } |
| 2872 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2873 | return false; |
| 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2876 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2879 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2880 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | enforceModifyPermission(); |
| 2882 | |
| 2883 | final long identity = Binder.clearCallingIdentity(); |
| 2884 | try { |
| 2885 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2886 | logv("Shutting down Phone " + i); |
| 2887 | shutdownRadioUsingPhoneId(i); |
| 2888 | } |
| 2889 | } finally { |
| 2890 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2895 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2896 | if (phone != null && phone.isRadioAvailable()) { |
| 2897 | phone.shutdownRadio(); |
| 2898 | } |
| 2899 | } |
| 2900 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2901 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2902 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2903 | |
| 2904 | final long identity = Binder.clearCallingIdentity(); |
| 2905 | try { |
| 2906 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2907 | if (defaultPhone != null) { |
| 2908 | defaultPhone.setRadioPower(turnOn); |
| 2909 | return true; |
| 2910 | } else { |
| 2911 | loge("There's no default phone."); |
| 2912 | return false; |
| 2913 | } |
| 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2916 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2919 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2921 | |
| 2922 | final long identity = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | final Phone phone = getPhone(subId); |
| 2925 | if (phone != null) { |
| 2926 | phone.setRadioPower(turnOn); |
| 2927 | return true; |
| 2928 | } else { |
| 2929 | return false; |
| 2930 | } |
| 2931 | } finally { |
| 2932 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2933 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2936 | /** |
| 2937 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2938 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2939 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2940 | * powering it off, and these radio off votes will be cleared. |
| 2941 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2942 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2943 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2944 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2945 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2946 | * check its vote. |
| 2947 | * |
| 2948 | * @param subId The subscription ID. |
| 2949 | * @param reason The reason for powering off radio. |
| 2950 | * @return true on success and false on failure. |
| 2951 | */ |
| 2952 | public boolean requestRadioPowerOffForReason(int subId, |
| 2953 | @TelephonyManager.RadioPowerReason int reason) { |
| 2954 | enforceModifyPermission(); |
| 2955 | |
| 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | final Phone phone = getPhone(subId); |
| 2959 | if (phone != null) { |
| 2960 | phone.setRadioPowerForReason(false, reason); |
| 2961 | return true; |
| 2962 | } else { |
| 2963 | return false; |
| 2964 | } |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | /** |
| 2971 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2972 | * {@link requestRadioPowerOffForReason}. |
| 2973 | * |
| 2974 | * @param subId The subscription ID. |
| 2975 | * @param reason The reason for powering off radio. |
| 2976 | * @return true on success and false on failure. |
| 2977 | */ |
| 2978 | public boolean clearRadioPowerOffForReason(int subId, |
| 2979 | @TelephonyManager.RadioPowerReason int reason) { |
| 2980 | enforceModifyPermission(); |
| 2981 | |
| 2982 | final long identity = Binder.clearCallingIdentity(); |
| 2983 | try { |
| 2984 | final Phone phone = getPhone(subId); |
| 2985 | if (phone != null) { |
| 2986 | phone.setRadioPowerForReason(true, reason); |
| 2987 | return true; |
| 2988 | } else { |
| 2989 | return false; |
| 2990 | } |
| 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | /** |
| 2997 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2998 | * |
| 2999 | * @param subId The subscription ID. |
| 3000 | * @param callingPackage The package making the call. |
| 3001 | * @param callingFeatureId The feature in the package. |
| 3002 | * @return List of reasons for powering off radio. |
| 3003 | */ |
| 3004 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3005 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3006 | |
| 3007 | final long identity = Binder.clearCallingIdentity(); |
| 3008 | List result = new ArrayList(); |
| 3009 | try { |
| 3010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3011 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3012 | return result; |
| 3013 | } |
| 3014 | |
| 3015 | final Phone phone = getPhone(subId); |
| 3016 | if (phone != null) { |
| 3017 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3018 | } |
| 3019 | } finally { |
| 3020 | Binder.restoreCallingIdentity(identity); |
| 3021 | } |
| 3022 | return result; |
| 3023 | } |
| 3024 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3025 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3026 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3027 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3028 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | |
| 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3032 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | final Phone phone = getPhone(subId); |
| 3034 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3035 | phone.getDataSettingsManager().setDataEnabled( |
| 3036 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | return true; |
| 3038 | } else { |
| 3039 | return false; |
| 3040 | } |
| 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3043 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3046 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3047 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3048 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3049 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | |
| 3051 | final long identity = Binder.clearCallingIdentity(); |
| 3052 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3053 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3054 | final Phone phone = getPhone(subId); |
| 3055 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3056 | phone.getDataSettingsManager().setDataEnabled( |
| 3057 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3058 | return true; |
| 3059 | } else { |
| 3060 | return false; |
| 3061 | } |
| 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3064 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3067 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3068 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | final Phone phone = getPhone(subId); |
| 3072 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3073 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | } else { |
| 3075 | return false; |
| 3076 | } |
| 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3079 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3083 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3086 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3087 | enforceCallPermission(); |
| 3088 | |
| 3089 | final long identity = Binder.clearCallingIdentity(); |
| 3090 | try { |
| 3091 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3092 | return; |
| 3093 | } |
| 3094 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3095 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(identity); |
| 3098 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3099 | }; |
| 3100 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3101 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3102 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3103 | |
| 3104 | final long identity = Binder.clearCallingIdentity(); |
| 3105 | try { |
| 3106 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3107 | return false; |
| 3108 | } |
| 3109 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3110 | } finally { |
| 3111 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3112 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3115 | /** |
| 3116 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3117 | * tag on getCallState Binder call. |
| 3118 | */ |
| 3119 | @Deprecated |
| 3120 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3122 | if (CompatChanges.isChangeEnabled( |
| 3123 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3124 | Binder.getCallingUid())) { |
| 3125 | // Do not allow this API to be called on API version 31+, it should only be |
| 3126 | // called on old apps using this Binder call directly. |
| 3127 | throw new SecurityException("This method can only be used for applications " |
| 3128 | + "targeting API version 30 or less."); |
| 3129 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3130 | final long identity = Binder.clearCallingIdentity(); |
| 3131 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3132 | Phone phone = getPhone(getDefaultSubscription()); |
| 3133 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3134 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
| 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | @Override |
| 3141 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3142 | if (CompatChanges.isChangeEnabled( |
| 3143 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3144 | Binder.getCallingUid())) { |
| 3145 | // Check READ_PHONE_STATE for API version 31+ |
| 3146 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3147 | featureId, "getCallStateForSubscription")) { |
| 3148 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3149 | + "targeting API level 31+."); |
| 3150 | } |
| 3151 | } |
| 3152 | final long identity = Binder.clearCallingIdentity(); |
| 3153 | try { |
| 3154 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3155 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3156 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
| 3159 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3162 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3163 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3164 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | @Override |
| 3168 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3171 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3172 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3173 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3174 | } else { |
| 3175 | return PhoneConstantConversions.convertDataState( |
| 3176 | PhoneConstants.DataState.DISCONNECTED); |
| 3177 | } |
| 3178 | } finally { |
| 3179 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3180 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3183 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3184 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3185 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3189 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3192 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3193 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3194 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | } else { |
| 3196 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3197 | } |
| 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3200 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3204 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3205 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3206 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3207 | |
| 3208 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3209 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3210 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3211 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3212 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3213 | .setCallingPid(Binder.getCallingPid()) |
| 3214 | .setCallingUid(Binder.getCallingUid()) |
| 3215 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3216 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3217 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3218 | .build()); |
| 3219 | switch (locationResult) { |
| 3220 | case DENIED_HARD: |
| 3221 | throw new SecurityException("Not allowed to access cell location"); |
| 3222 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3223 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3224 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3227 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3231 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3232 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | } finally { |
| 3234 | Binder.restoreCallingIdentity(identity); |
| 3235 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3238 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3239 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3240 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3241 | // registered cell info, so return a NULL country instead. |
| 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3244 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3245 | // Get default phone in this case. |
| 3246 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3247 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3248 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3249 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3250 | if (phone == null) return ""; |
| 3251 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3252 | if (sst == null) return ""; |
| 3253 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3254 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3255 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(identity); |
| 3258 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3261 | /** |
| 3262 | * This method was removed due to potential issues caused by performing partial |
| 3263 | * updates of service state, and lack of a credible use case. |
| 3264 | * |
| 3265 | * This has the ability to break the telephony implementation by disabling notification of |
| 3266 | * changes in device connectivity. DO NOT USE THIS! |
| 3267 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3268 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3269 | public void enableLocationUpdates() { |
| 3270 | mApp.enforceCallingOrSelfPermission( |
| 3271 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3274 | /** |
| 3275 | * This method was removed due to potential issues caused by performing partial |
| 3276 | * updates of service state, and lack of a credible use case. |
| 3277 | * |
| 3278 | * This has the ability to break the telephony implementation by disabling notification of |
| 3279 | * changes in device connectivity. DO NOT USE THIS! |
| 3280 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3281 | @Override |
| 3282 | public void disableLocationUpdates() { |
| 3283 | mApp.enforceCallingOrSelfPermission( |
| 3284 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | @Override |
| 3288 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3289 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3290 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3291 | try { |
| 3292 | mApp.getSystemService(AppOpsManager.class) |
| 3293 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3294 | } catch (SecurityException e) { |
| 3295 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3296 | throw e; |
| 3297 | } |
| 3298 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3299 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3300 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3301 | throw new SecurityException( |
| 3302 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3303 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3304 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3305 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3306 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3307 | return null; |
| 3308 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3309 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3310 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3311 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3312 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3313 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3314 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3315 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3316 | for (CellInfo ci : info) { |
| 3317 | if (ci instanceof CellInfoGsm) { |
| 3318 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3319 | } else if (ci instanceof CellInfoWcdma) { |
| 3320 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3322 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3323 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3324 | } |
| 3325 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3326 | private List<CellInfo> getCachedCellInfo() { |
| 3327 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3328 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3329 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3330 | if (info != null) cellInfos.addAll(info); |
| 3331 | } |
| 3332 | return cellInfos; |
| 3333 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3334 | |
| 3335 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3336 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3337 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3338 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3339 | |
| 3340 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3341 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3342 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3343 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3344 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3345 | .setCallingPid(Binder.getCallingPid()) |
| 3346 | .setCallingUid(Binder.getCallingUid()) |
| 3347 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3348 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3349 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3350 | .build()); |
| 3351 | switch (locationResult) { |
| 3352 | case DENIED_HARD: |
| 3353 | throw new SecurityException("Not allowed to access cell info"); |
| 3354 | case DENIED_SOFT: |
| 3355 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3358 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3359 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3360 | return getCachedCellInfo(); |
| 3361 | } |
| 3362 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3363 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3364 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3365 | final long identity = Binder.clearCallingIdentity(); |
| 3366 | try { |
| 3367 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3368 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3369 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3370 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3371 | if (info != null) cellInfos.addAll(info); |
| 3372 | } |
| 3373 | return cellInfos; |
| 3374 | } finally { |
| 3375 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3379 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3380 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3381 | String callingFeatureId) { |
| 3382 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3383 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3387 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3388 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3389 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3390 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3393 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3394 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3395 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3396 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3397 | |
| 3398 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3399 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3400 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3401 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3402 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3403 | .setCallingPid(Binder.getCallingPid()) |
| 3404 | .setCallingUid(Binder.getCallingUid()) |
| 3405 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3406 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3407 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3408 | .build()); |
| 3409 | switch (locationResult) { |
| 3410 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3411 | if (TelephonyPermissions |
| 3412 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3413 | // Safetynet logging for b/154934934 |
| 3414 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3415 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3416 | throw new SecurityException("Not allowed to access cell info"); |
| 3417 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3418 | if (TelephonyPermissions |
| 3419 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3420 | // Safetynet logging for b/154934934 |
| 3421 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3422 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3423 | try { |
| 3424 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3425 | } catch (RemoteException re) { |
| 3426 | // Drop without consequences |
| 3427 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3428 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3431 | |
| 3432 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3433 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3434 | |
| 3435 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3436 | } |
| 3437 | |
| 3438 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3439 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3440 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3441 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3442 | |
| 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3445 | Phone phone = getPhone(subId); |
| 3446 | if (phone == null) { |
| 3447 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3448 | } else { |
| 3449 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3450 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3451 | } finally { |
| 3452 | Binder.restoreCallingIdentity(identity); |
| 3453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3457 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3458 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3459 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3460 | return null; |
| 3461 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3462 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3463 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3464 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3465 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3466 | return null; |
| 3467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3468 | |
| 3469 | final long identity = Binder.clearCallingIdentity(); |
| 3470 | try { |
| 3471 | return phone.getImei(); |
| 3472 | } finally { |
| 3473 | Binder.restoreCallingIdentity(identity); |
| 3474 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3478 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3479 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3480 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3481 | callingFeatureId, "getPrimaryImei")) { |
| 3482 | throw new SecurityException("Caller does not have permission"); |
| 3483 | } |
| 3484 | final long identity = Binder.clearCallingIdentity(); |
| 3485 | try { |
| 3486 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3487 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3488 | return phone.getImei(); |
| 3489 | } |
| 3490 | } |
| 3491 | throw new UnsupportedOperationException("Operation not supported"); |
| 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(identity); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3498 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3499 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3500 | String tac = null; |
| 3501 | if (phone != null) { |
| 3502 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3503 | try { |
| 3504 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3505 | } catch (IndexOutOfBoundsException e) { |
| 3506 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3507 | return null; |
| 3508 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3509 | } |
| 3510 | return tac; |
| 3511 | } |
| 3512 | |
| 3513 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3514 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3515 | try { |
| 3516 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3517 | } catch (SecurityException se) { |
| 3518 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3519 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3520 | + Binder.getCallingUid()); |
| 3521 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3522 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3523 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3524 | return null; |
| 3525 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3526 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3527 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3528 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3529 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3530 | return null; |
| 3531 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | |
| 3533 | final long identity = Binder.clearCallingIdentity(); |
| 3534 | try { |
| 3535 | return phone.getMeid(); |
| 3536 | } finally { |
| 3537 | Binder.restoreCallingIdentity(identity); |
| 3538 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3542 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3543 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3544 | String manufacturerCode = null; |
| 3545 | if (phone != null) { |
| 3546 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3547 | try { |
| 3548 | manufacturerCode = |
| 3549 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3550 | } catch (IndexOutOfBoundsException e) { |
| 3551 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3552 | return null; |
| 3553 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3554 | } |
| 3555 | return manufacturerCode; |
| 3556 | } |
| 3557 | |
| 3558 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3559 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3560 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3561 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3562 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3563 | return null; |
| 3564 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3565 | int subId = phone.getSubId(); |
| 3566 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3567 | mApp, subId, callingPackage, callingFeatureId, |
| 3568 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3569 | return null; |
| 3570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3571 | |
| 3572 | final long identity = Binder.clearCallingIdentity(); |
| 3573 | try { |
| 3574 | return phone.getDeviceSvn(); |
| 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
| 3577 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3580 | @Override |
| 3581 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3582 | final long identity = Binder.clearCallingIdentity(); |
| 3583 | try { |
| 3584 | final Phone phone = getPhone(subId); |
| 3585 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
| 3588 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | @Override |
| 3592 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | final Phone phone = getPhone(subId); |
| 3596 | return phone == null ? null : phone.getCarrierName(); |
| 3597 | } finally { |
| 3598 | Binder.restoreCallingIdentity(identity); |
| 3599 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3600 | } |
| 3601 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3602 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3603 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3604 | final long identity = Binder.clearCallingIdentity(); |
| 3605 | try { |
| 3606 | final Phone phone = getPhone(subId); |
| 3607 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3608 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3615 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3619 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3620 | } finally { |
| 3621 | Binder.restoreCallingIdentity(identity); |
| 3622 | } |
| 3623 | } |
| 3624 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3625 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3626 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3627 | if (!isSubscriptionMccMnc) { |
| 3628 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3629 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3630 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3631 | if (phone == null) { |
| 3632 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3633 | } |
| 3634 | final long identity = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(identity); |
| 3639 | } |
| 3640 | } |
| 3641 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3642 | // |
| 3643 | // Internal helper methods. |
| 3644 | // |
| 3645 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3646 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3647 | * Make sure the caller is the calling package itself |
| 3648 | * |
| 3649 | * @throws SecurityException if the caller is not the calling package |
| 3650 | */ |
| 3651 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3652 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3653 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3654 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3655 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3656 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3657 | } catch (PackageManager.NameNotFoundException e) { |
| 3658 | // packageUid is -1 |
| 3659 | } |
| 3660 | if (packageUid != callingUid) { |
| 3661 | throw new SecurityException(message + ": Package " + callingPackage |
| 3662 | + " does not belong to " + callingUid); |
| 3663 | } |
| 3664 | } |
| 3665 | |
| 3666 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3667 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3668 | * |
| 3669 | * @throws SecurityException if the caller does not have the required permission |
| 3670 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3671 | @VisibleForTesting |
| 3672 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3673 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3674 | } |
| 3675 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3676 | /** |
| 3677 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3678 | * |
| 3679 | * @throws SecurityException if the caller does not have the required permission |
| 3680 | */ |
| 3681 | @VisibleForTesting |
| 3682 | public void enforceReadPermission() { |
| 3683 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 3684 | } |
| 3685 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3686 | private void enforceActiveEmergencySessionPermission() { |
| 3687 | mApp.enforceCallingOrSelfPermission( |
| 3688 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3689 | } |
| 3690 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3691 | /** |
| 3692 | * Make sure the caller has the CALL_PHONE permission. |
| 3693 | * |
| 3694 | * @throws SecurityException if the caller does not have the required permission |
| 3695 | */ |
| 3696 | private void enforceCallPermission() { |
| 3697 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3698 | } |
| 3699 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3700 | private void enforceSettingsPermission() { |
| 3701 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3704 | private void enforceRebootPermission() { |
| 3705 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3706 | } |
| 3707 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3708 | private String createTelUrl(String number) { |
| 3709 | if (TextUtils.isEmpty(number)) { |
| 3710 | return null; |
| 3711 | } |
| 3712 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3713 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3716 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3717 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3718 | } |
| 3719 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3720 | private static void logv(String msg) { |
| 3721 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3722 | } |
| 3723 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3724 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3725 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3726 | } |
| 3727 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3728 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3729 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3730 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3733 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3734 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3735 | final long identity = Binder.clearCallingIdentity(); |
| 3736 | try { |
| 3737 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3738 | if (phone == null) { |
| 3739 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3740 | } else { |
| 3741 | return phone.getPhoneType(); |
| 3742 | } |
| 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3745 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | /** |
| 3749 | * Returns the CDMA ERI icon index to display |
| 3750 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3751 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3752 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3753 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3754 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3757 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3758 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3759 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3761 | mApp, subId, callingPackage, callingFeatureId, |
| 3762 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3763 | return -1; |
| 3764 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3765 | |
| 3766 | final long identity = Binder.clearCallingIdentity(); |
| 3767 | try { |
| 3768 | final Phone phone = getPhone(subId); |
| 3769 | if (phone != null) { |
| 3770 | return phone.getCdmaEriIconIndex(); |
| 3771 | } else { |
| 3772 | return -1; |
| 3773 | } |
| 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | /** |
| 3780 | * Returns the CDMA ERI icon mode, |
| 3781 | * 0 - ON |
| 3782 | * 1 - FLASHING |
| 3783 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3784 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3785 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3786 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3787 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3790 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3791 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3792 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3793 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3794 | mApp, subId, callingPackage, callingFeatureId, |
| 3795 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3796 | return -1; |
| 3797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | |
| 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
| 3801 | final Phone phone = getPhone(subId); |
| 3802 | if (phone != null) { |
| 3803 | return phone.getCdmaEriIconMode(); |
| 3804 | } else { |
| 3805 | return -1; |
| 3806 | } |
| 3807 | } finally { |
| 3808 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3809 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | /** |
| 3813 | * Returns the CDMA ERI text, |
| 3814 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3815 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3816 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3817 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3818 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3821 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3822 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3823 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3824 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3825 | mApp, subId, callingPackage, callingFeatureId, |
| 3826 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3827 | return null; |
| 3828 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3829 | |
| 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | final Phone phone = getPhone(subId); |
| 3833 | if (phone != null) { |
| 3834 | return phone.getCdmaEriText(); |
| 3835 | } else { |
| 3836 | return null; |
| 3837 | } |
| 3838 | } finally { |
| 3839 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3840 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3844 | * Returns the CDMA MDN. |
| 3845 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3846 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3847 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3849 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3850 | |
| 3851 | final long identity = Binder.clearCallingIdentity(); |
| 3852 | try { |
| 3853 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3854 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | return phone.getLine1Number(); |
| 3856 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3857 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3858 | return null; |
| 3859 | } |
| 3860 | } finally { |
| 3861 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | /** |
| 3866 | * Returns the CDMA MIN. |
| 3867 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3868 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3869 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3870 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3871 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3872 | |
| 3873 | final long identity = Binder.clearCallingIdentity(); |
| 3874 | try { |
| 3875 | final Phone phone = getPhone(subId); |
| 3876 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3877 | return phone.getCdmaMin(); |
| 3878 | } else { |
| 3879 | return null; |
| 3880 | } |
| 3881 | } finally { |
| 3882 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3883 | } |
| 3884 | } |
| 3885 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3886 | @Override |
| 3887 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3888 | INumberVerificationCallback callback, String callingPackage) { |
| 3889 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3890 | != PERMISSION_GRANTED) { |
| 3891 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3892 | } |
| 3893 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3894 | |
| 3895 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3896 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3897 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3898 | + "calling package: " + callingPackage |
| 3899 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | if (range == null) { |
| 3903 | throw new NullPointerException("Range must be non-null"); |
| 3904 | } |
| 3905 | |
| 3906 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3907 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3908 | |
| 3909 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3910 | } |
| 3911 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3912 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3913 | * Returns true if CDMA provisioning needs to run. |
| 3914 | */ |
| 3915 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3916 | final long identity = Binder.clearCallingIdentity(); |
| 3917 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3918 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3919 | } finally { |
| 3920 | Binder.restoreCallingIdentity(identity); |
| 3921 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3925 | * Sets the voice mail number of a given subId. |
| 3926 | */ |
| 3927 | @Override |
| 3928 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3929 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3930 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3931 | |
| 3932 | final long identity = Binder.clearCallingIdentity(); |
| 3933 | try { |
| 3934 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3935 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3936 | return success; |
| 3937 | } finally { |
| 3938 | Binder.restoreCallingIdentity(identity); |
| 3939 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3940 | } |
| 3941 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3942 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3943 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3944 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3945 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3946 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3947 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3948 | throw new SecurityException("caller must be system dialer"); |
| 3949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | |
| 3951 | final long identity = Binder.clearCallingIdentity(); |
| 3952 | try { |
| 3953 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3954 | if (phoneAccountHandle == null) { |
| 3955 | return null; |
| 3956 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3960 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3964 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3965 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3966 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3967 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3968 | mApp, subId, callingPackage, callingFeatureId, |
| 3969 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3970 | return null; |
| 3971 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3973 | final long identity = Binder.clearCallingIdentity(); |
| 3974 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3975 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(identity); |
| 3978 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3982 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3983 | VisualVoicemailSmsFilterSettings settings) { |
| 3984 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3985 | |
| 3986 | final long identity = Binder.clearCallingIdentity(); |
| 3987 | try { |
| 3988 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3989 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3990 | } finally { |
| 3991 | Binder.restoreCallingIdentity(identity); |
| 3992 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3996 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3997 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | |
| 3999 | final long identity = Binder.clearCallingIdentity(); |
| 4000 | try { |
| 4001 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4002 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4003 | } finally { |
| 4004 | Binder.restoreCallingIdentity(identity); |
| 4005 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4009 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4010 | String callingPackage, int subId) { |
| 4011 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4012 | |
| 4013 | final long identity = Binder.clearCallingIdentity(); |
| 4014 | try { |
| 4015 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4016 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4023 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4025 | |
| 4026 | final long identity = Binder.clearCallingIdentity(); |
| 4027 | try { |
| 4028 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4029 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | } finally { |
| 4031 | Binder.restoreCallingIdentity(identity); |
| 4032 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4036 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4037 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4038 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4039 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4040 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4041 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4042 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4043 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4044 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4045 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4046 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4047 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4048 | * Sets the voice activation state of a given subId. |
| 4049 | */ |
| 4050 | @Override |
| 4051 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4052 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4053 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | |
| 4055 | final long identity = Binder.clearCallingIdentity(); |
| 4056 | try { |
| 4057 | final Phone phone = getPhone(subId); |
| 4058 | if (phone != null) { |
| 4059 | phone.setVoiceActivationState(activationState); |
| 4060 | } else { |
| 4061 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4062 | } |
| 4063 | } finally { |
| 4064 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | /** |
| 4069 | * Sets the data activation state of a given subId. |
| 4070 | */ |
| 4071 | @Override |
| 4072 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4074 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4075 | |
| 4076 | final long identity = Binder.clearCallingIdentity(); |
| 4077 | try { |
| 4078 | final Phone phone = getPhone(subId); |
| 4079 | if (phone != null) { |
| 4080 | phone.setDataActivationState(activationState); |
| 4081 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4082 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | } |
| 4084 | } finally { |
| 4085 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | /** |
| 4090 | * Returns the voice activation state of a given subId. |
| 4091 | */ |
| 4092 | @Override |
| 4093 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4096 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4097 | final long identity = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | if (phone != null) { |
| 4100 | return phone.getVoiceActivationState(); |
| 4101 | } else { |
| 4102 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4103 | } |
| 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | /** |
| 4110 | * Returns the data activation state of a given subId. |
| 4111 | */ |
| 4112 | @Override |
| 4113 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4114 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4115 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4116 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | if (phone != null) { |
| 4120 | return phone.getDataActivationState(); |
| 4121 | } else { |
| 4122 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4123 | } |
| 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4130 | * Returns the unread count of voicemails for a subId |
| 4131 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4132 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4133 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4134 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4135 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4136 | mApp, subId, callingPackage, callingFeatureId, |
| 4137 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4138 | return 0; |
| 4139 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
| 4142 | final Phone phone = getPhone(subId); |
| 4143 | if (phone != null) { |
| 4144 | return phone.getVoiceMessageCount(); |
| 4145 | } else { |
| 4146 | return 0; |
| 4147 | } |
| 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4154 | * returns true, if the device is in a state where both voice and data |
| 4155 | * are supported simultaneously. This can change based on location or network condition. |
| 4156 | */ |
| 4157 | @Override |
| 4158 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4159 | final long identity = Binder.clearCallingIdentity(); |
| 4160 | try { |
| 4161 | final Phone phone = getPhone(subId); |
| 4162 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4163 | } finally { |
| 4164 | Binder.restoreCallingIdentity(identity); |
| 4165 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4169 | * Send the dialer code if called from the current default dialer or the caller has |
| 4170 | * carrier privilege. |
| 4171 | * @param inputCode The dialer code to send |
| 4172 | */ |
| 4173 | @Override |
| 4174 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4175 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4176 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4177 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4178 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4179 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4180 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4181 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4182 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | |
| 4184 | final long identity = Binder.clearCallingIdentity(); |
| 4185 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4186 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4187 | } finally { |
| 4188 | Binder.restoreCallingIdentity(identity); |
| 4189 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4192 | @Override |
| 4193 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4194 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4195 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4196 | mApp, subId, "getNetworkSelectionMode"); |
| 4197 | final long identity = Binder.clearCallingIdentity(); |
| 4198 | try { |
| 4199 | if (!isActiveSubscription(subId)) { |
| 4200 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4201 | } |
| 4202 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4203 | } finally { |
| 4204 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4205 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4208 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4209 | public boolean isInEmergencySmsMode() { |
| 4210 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4211 | final long identity = Binder.clearCallingIdentity(); |
| 4212 | try { |
| 4213 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4214 | if (phone.isInEmergencySmsMode()) { |
| 4215 | return true; |
| 4216 | } |
| 4217 | } |
| 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
| 4221 | return false; |
| 4222 | } |
| 4223 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4224 | /** |
| 4225 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4226 | * @param subId The subscription to use to check the configuration. |
| 4227 | * @param c The callback that will be used to send the result. |
| 4228 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4229 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4230 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4231 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4232 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4233 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4234 | |
| 4235 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4236 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4237 | "IMS not available on device."); |
| 4238 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4239 | final long token = Binder.clearCallingIdentity(); |
| 4240 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4241 | int slotId = getSlotIndexOrException(subId); |
| 4242 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4243 | |
| 4244 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4245 | if (controller != null) { |
| 4246 | ImsManager imsManager = controller.getImsManager(subId); |
| 4247 | if (imsManager != null) { |
| 4248 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4249 | } else { |
| 4250 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4251 | } |
| 4252 | } else { |
| 4253 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4254 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4255 | } catch (ImsException e) { |
| 4256 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4257 | } finally { |
| 4258 | Binder.restoreCallingIdentity(token); |
| 4259 | } |
| 4260 | } |
| 4261 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4262 | /** |
| 4263 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4264 | * @param subId The subscription to use to check the configuration. |
| 4265 | * @param c The callback that will be used to send the result. |
| 4266 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4267 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4268 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4269 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4270 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4271 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4272 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4273 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4274 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4275 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4276 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4277 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4278 | if (controller != null) { |
| 4279 | ImsManager imsManager = controller.getImsManager(subId); |
| 4280 | if (imsManager != null) { |
| 4281 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4282 | } else { |
| 4283 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4284 | + "is inactive, ignoring unregister."); |
| 4285 | // If the ImsManager is not valid, just return, since the callback |
| 4286 | // will already have been removed internally. |
| 4287 | } |
| 4288 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4289 | } finally { |
| 4290 | Binder.restoreCallingIdentity(token); |
| 4291 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4294 | /** |
| 4295 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4296 | */ |
| 4297 | @Override |
| 4298 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4299 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4300 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4301 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4302 | "IMS not available on device."); |
| 4303 | } |
| 4304 | final long token = Binder.clearCallingIdentity(); |
| 4305 | try { |
| 4306 | Phone phone = getPhone(subId); |
| 4307 | if (phone == null) { |
| 4308 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4309 | + subId + "'"); |
| 4310 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4311 | } |
| 4312 | phone.getImsRegistrationState(regState -> { |
| 4313 | try { |
| 4314 | consumer.accept((regState == null) |
| 4315 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4316 | } catch (RemoteException e) { |
| 4317 | // Ignore if the remote process is no longer available to call back. |
| 4318 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4319 | } |
| 4320 | }); |
| 4321 | } finally { |
| 4322 | Binder.restoreCallingIdentity(token); |
| 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | /** |
| 4327 | * Get the transport type for the IMS service registration state. |
| 4328 | */ |
| 4329 | @Override |
| 4330 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4331 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4332 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4333 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4334 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4335 | "IMS not available on device."); |
| 4336 | } |
| 4337 | final long token = Binder.clearCallingIdentity(); |
| 4338 | try { |
| 4339 | Phone phone = getPhone(subId); |
| 4340 | if (phone == null) { |
| 4341 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4342 | + subId + "'"); |
| 4343 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4344 | } |
| 4345 | phone.getImsRegistrationTech(regTech -> { |
| 4346 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4347 | int regTechConverted = (regTech == null) |
| 4348 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4349 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4350 | regTechConverted); |
| 4351 | try { |
| 4352 | consumer.accept(regTechConverted); |
| 4353 | } catch (RemoteException e) { |
| 4354 | // Ignore if the remote process is no longer available to call back. |
| 4355 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4356 | } |
| 4357 | }); |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(token); |
| 4360 | } |
| 4361 | } |
| 4362 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4363 | /** |
| 4364 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4365 | * @param subId The subscription to use to check the configuration. |
| 4366 | * @param c The callback that will be used to send the result. |
| 4367 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4368 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4369 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4370 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4371 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4372 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4373 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4374 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4375 | "IMS not available on device."); |
| 4376 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4377 | final long token = Binder.clearCallingIdentity(); |
| 4378 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4379 | int slotId = getSlotIndexOrException(subId); |
| 4380 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4381 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4382 | } catch (ImsException e) { |
| 4383 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(token); |
| 4386 | } |
| 4387 | } |
| 4388 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4389 | /** |
| 4390 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4391 | * @param subId The subscription to use to check the configuration. |
| 4392 | * @param c The callback that will be used to send the result. |
| 4393 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4394 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4395 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4396 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4397 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4398 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4399 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4400 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4401 | |
| 4402 | final long token = Binder.clearCallingIdentity(); |
| 4403 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4404 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4405 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4406 | } catch (ImsException e) { |
| 4407 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4408 | + "is inactive, ignoring unregister."); |
| 4409 | // If the subscription is no longer active, just return, since the callback |
| 4410 | // will already have been removed internally. |
| 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(token); |
| 4413 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4417 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4418 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4419 | final long token = Binder.clearCallingIdentity(); |
| 4420 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4421 | int slotId = getSlotIndexOrException(subId); |
| 4422 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4423 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4424 | } catch (com.android.ims.ImsException e) { |
| 4425 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4426 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4427 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4428 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4429 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4430 | } finally { |
| 4431 | Binder.restoreCallingIdentity(token); |
| 4432 | } |
| 4433 | } |
| 4434 | |
| 4435 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4436 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4437 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4438 | final long token = Binder.clearCallingIdentity(); |
| 4439 | try { |
| 4440 | Phone phone = getPhone(subId); |
| 4441 | if (phone == null) return false; |
| 4442 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4443 | } catch (com.android.ims.ImsException e) { |
| 4444 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4445 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4446 | } finally { |
| 4447 | Binder.restoreCallingIdentity(token); |
| 4448 | } |
| 4449 | } |
| 4450 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4451 | /** |
| 4452 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4453 | * subscription. |
| 4454 | * @param subId The subscription to use to check the configuration. |
| 4455 | * @param callback The callback that will be used to send the result. |
| 4456 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4457 | * @param transportType The transport type of the MmTelFeature capability. |
| 4458 | */ |
| 4459 | @Override |
| 4460 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4461 | int transportType) { |
| 4462 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4463 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4464 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4465 | "IMS not available on device."); |
| 4466 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4467 | final long token = Binder.clearCallingIdentity(); |
| 4468 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4469 | int slotId = getSlotIndex(subId); |
| 4470 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4471 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4472 | + subId + "'"); |
| 4473 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4474 | } |
| 4475 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4476 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4477 | transportType, aBoolean -> { |
| 4478 | try { |
| 4479 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4480 | } catch (RemoteException e) { |
| 4481 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4482 | + "running. Ignore"); |
| 4483 | } |
| 4484 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4485 | } catch (ImsException e) { |
| 4486 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(token); |
| 4489 | } |
| 4490 | } |
| 4491 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4492 | /** |
| 4493 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4494 | * @param subId The subscription to use to check the configuration. |
| 4495 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4496 | @Override |
| 4497 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4498 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4499 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4500 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4501 | final long token = Binder.clearCallingIdentity(); |
| 4502 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4503 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4504 | // 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] | 4505 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4506 | } catch (ImsException e) { |
| 4507 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(token); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4514 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4516 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4519 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4520 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4521 | // 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] | 4522 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4523 | } catch (ImsException e) { |
| 4524 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(identity); |
| 4527 | } |
| 4528 | } |
| 4529 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4530 | /** |
| 4531 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4532 | * @param subId The subscription to use to check the configuration. |
| 4533 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4534 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4535 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4536 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4537 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4538 | final long identity = Binder.clearCallingIdentity(); |
| 4539 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4540 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4541 | // 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] | 4542 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4543 | } catch (ImsException e) { |
| 4544 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4545 | } finally { |
| 4546 | Binder.restoreCallingIdentity(identity); |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4551 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4553 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4554 | final long identity = Binder.clearCallingIdentity(); |
| 4555 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4556 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4557 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4558 | // 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] | 4559 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4560 | } catch (ImsException e) { |
| 4561 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4562 | } finally { |
| 4563 | Binder.restoreCallingIdentity(identity); |
| 4564 | } |
| 4565 | } |
| 4566 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4567 | /** |
| 4568 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4569 | * @param subId The subscription to use to check the configuration. |
| 4570 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4571 | @Override |
| 4572 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4573 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4574 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4575 | final long identity = Binder.clearCallingIdentity(); |
| 4576 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4577 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4578 | // 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] | 4579 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4580 | } catch (ImsException e) { |
| 4581 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
| 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4588 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4590 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4593 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4594 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4595 | // 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] | 4596 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4597 | } catch (ImsException e) { |
| 4598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
| 4601 | } |
| 4602 | } |
| 4603 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4604 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4605 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4606 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4607 | * @param subId The subscription to use to check the configuration. |
| 4608 | */ |
| 4609 | @Override |
| 4610 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4611 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4612 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4615 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4616 | // 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] | 4617 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4618 | } catch (ImsException e) { |
| 4619 | throw new ServiceSpecificException(e.getCode()); |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | /** |
| 4626 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4627 | * Requires MODIFY_PHONE_STATE permission. |
| 4628 | * @param subId The subscription to use to check the configuration. |
| 4629 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4630 | * false otherwise |
| 4631 | */ |
| 4632 | @Override |
| 4633 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4635 | "setCrossSimCallingEnabled"); |
| 4636 | final long identity = Binder.clearCallingIdentity(); |
| 4637 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4638 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4639 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4640 | // 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] | 4641 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4642 | } catch (ImsException e) { |
| 4643 | throw new ServiceSpecificException(e.getCode()); |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(identity); |
| 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4650 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4651 | * @param subId The subscription to use to check the configuration. |
| 4652 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4653 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4654 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4655 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4656 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4657 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4658 | final long identity = Binder.clearCallingIdentity(); |
| 4659 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4660 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4661 | // 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] | 4662 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4663 | } catch (ImsException e) { |
| 4664 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4671 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4673 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4674 | final long identity = Binder.clearCallingIdentity(); |
| 4675 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4676 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4677 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4678 | // 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] | 4679 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4680 | } catch (ImsException e) { |
| 4681 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4682 | } finally { |
| 4683 | Binder.restoreCallingIdentity(identity); |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | @Override |
| 4688 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4690 | "setVoWiFiNonPersistent"); |
| 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4693 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4694 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4695 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4696 | } catch (ImsException e) { |
| 4697 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(identity); |
| 4700 | } |
| 4701 | } |
| 4702 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4703 | /** |
| 4704 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4705 | * @param subId The subscription to use to check the configuration. |
| 4706 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4707 | @Override |
| 4708 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4709 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4710 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4711 | final long identity = Binder.clearCallingIdentity(); |
| 4712 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4713 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4714 | // 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] | 4715 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4716 | } catch (ImsException e) { |
| 4717 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4718 | } finally { |
| 4719 | Binder.restoreCallingIdentity(identity); |
| 4720 | } |
| 4721 | } |
| 4722 | |
| 4723 | @Override |
| 4724 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4725 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4726 | "setVoWiFiModeSetting"); |
| 4727 | final long identity = Binder.clearCallingIdentity(); |
| 4728 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4729 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4730 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4731 | // 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] | 4732 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4733 | } catch (ImsException e) { |
| 4734 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4735 | } finally { |
| 4736 | Binder.restoreCallingIdentity(identity); |
| 4737 | } |
| 4738 | } |
| 4739 | |
| 4740 | @Override |
| 4741 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4742 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4743 | final long identity = Binder.clearCallingIdentity(); |
| 4744 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4745 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4746 | // 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] | 4747 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4748 | } catch (ImsException e) { |
| 4749 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(identity); |
| 4752 | } |
| 4753 | } |
| 4754 | |
| 4755 | @Override |
| 4756 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4758 | "setVoWiFiRoamingModeSetting"); |
| 4759 | final long identity = Binder.clearCallingIdentity(); |
| 4760 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4761 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4762 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4763 | // 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] | 4764 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4765 | } catch (ImsException e) { |
| 4766 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(identity); |
| 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | @Override |
| 4773 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4775 | "setRttCapabilityEnabled"); |
| 4776 | final long identity = Binder.clearCallingIdentity(); |
| 4777 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4778 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4779 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4780 | // 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] | 4781 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4782 | } catch (ImsException e) { |
| 4783 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4784 | } finally { |
| 4785 | Binder.restoreCallingIdentity(identity); |
| 4786 | } |
| 4787 | } |
| 4788 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4789 | /** |
| 4790 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4791 | * @param subId The subscription to use to check the configuration. |
| 4792 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4793 | @Override |
| 4794 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4795 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4796 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4797 | final long identity = Binder.clearCallingIdentity(); |
| 4798 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4799 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4800 | // 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] | 4801 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4802 | } catch (ImsException e) { |
| 4803 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4804 | } finally { |
| 4805 | Binder.restoreCallingIdentity(identity); |
| 4806 | } |
| 4807 | } |
| 4808 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4809 | @Override |
| 4810 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4811 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4812 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4813 | final long identity = Binder.clearCallingIdentity(); |
| 4814 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4815 | if (!isImsAvailableOnDevice()) { |
| 4816 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4817 | "IMS not available on device."); |
| 4818 | } |
| 4819 | int slotId = getSlotIndexOrException(subId); |
| 4820 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4821 | ImsManager.getInstance(mApp, slotId) |
| 4822 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4823 | } catch (ImsException e) { |
| 4824 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4825 | } finally { |
| 4826 | Binder.restoreCallingIdentity(identity); |
| 4827 | } |
| 4828 | } |
| 4829 | |
| 4830 | @Override |
| 4831 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4832 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4833 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4834 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4835 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4836 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4837 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4838 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4839 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4840 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4841 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4842 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4843 | + "is inactive, ignoring unregister."); |
| 4844 | // If the subscription is no longer active, just return, since the callback will already |
| 4845 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4846 | } finally { |
| 4847 | Binder.restoreCallingIdentity(identity); |
| 4848 | } |
| 4849 | } |
| 4850 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4851 | @Override |
| 4852 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4853 | IFeatureProvisioningCallback callback) { |
| 4854 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4855 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4856 | |
| 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4859 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4860 | } |
| 4861 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4862 | try { |
| 4863 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4864 | if (controller == null) { |
| 4865 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4866 | "Device does not support IMS"); |
| 4867 | } |
| 4868 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(identity); |
| 4871 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | @Override |
| 4875 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4876 | IFeatureProvisioningCallback callback) { |
| 4877 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4878 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4879 | |
| 4880 | final long identity = Binder.clearCallingIdentity(); |
| 4881 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4882 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4883 | } |
| 4884 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4885 | try { |
| 4886 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4887 | if (controller == null) { |
| 4888 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4889 | return; |
| 4890 | } |
| 4891 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4892 | } finally { |
| 4893 | Binder.restoreCallingIdentity(identity); |
| 4894 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4895 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4896 | |
| 4897 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4899 | message); |
| 4900 | } |
| 4901 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4902 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4903 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4904 | boolean isProvisioned) { |
| 4905 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4906 | |
| 4907 | final long identity = Binder.clearCallingIdentity(); |
| 4908 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4909 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4910 | if (controller == null) { |
| 4911 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4912 | return; |
| 4913 | } |
| 4914 | controller.setRcsProvisioningStatusForCapability( |
| 4915 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | |
| 4922 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4923 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4924 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4925 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4926 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4929 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4930 | if (controller == null) { |
| 4931 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4932 | |
| 4933 | // device does not support IMS, this method will return true always. |
| 4934 | return true; |
| 4935 | } |
| 4936 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
| 4940 | } |
| 4941 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4942 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4943 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4944 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4945 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4946 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4947 | final long identity = Binder.clearCallingIdentity(); |
| 4948 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4949 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4950 | if (controller == null) { |
| 4951 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4952 | return; |
| 4953 | } |
| 4954 | controller.setImsProvisioningStatusForCapability( |
| 4955 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4956 | } finally { |
| 4957 | Binder.restoreCallingIdentity(identity); |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | @Override |
| 4962 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4963 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4964 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4965 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4966 | final long identity = Binder.clearCallingIdentity(); |
| 4967 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4968 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4969 | if (controller == null) { |
| 4970 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4971 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4972 | // device does not support IMS, this method will return true always. |
| 4973 | return true; |
| 4974 | } |
| 4975 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
| 4978 | } |
| 4979 | } |
| 4980 | |
| 4981 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4982 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4983 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4984 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4985 | |
| 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4988 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4989 | if (controller == null) { |
| 4990 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4991 | |
| 4992 | // device does not support IMS, this method will return false |
| 4993 | return false; |
| 4994 | } |
| 4995 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4998 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5002 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5003 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5004 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5005 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5008 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5009 | if (controller == null) { |
| 5010 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5011 | |
| 5012 | // device does not support IMS, this method will return false |
| 5013 | return false; |
| 5014 | } |
| 5015 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5016 | } finally { |
| 5017 | Binder.restoreCallingIdentity(identity); |
| 5018 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5019 | } |
| 5020 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5021 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5022 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5023 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5024 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5025 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5026 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5027 | mApp, subId, "getImsProvisioningInt"); |
| 5028 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5029 | final long identity = Binder.clearCallingIdentity(); |
| 5030 | try { |
| 5031 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5032 | int slotId = getSlotIndex(subId); |
| 5033 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5034 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5035 | + subId + "' for key:" + key); |
| 5036 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5037 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5038 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5039 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5040 | if (controller == null) { |
| 5041 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5042 | |
| 5043 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5044 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5045 | } |
| 5046 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5047 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5048 | return retVal; |
| 5049 | } |
| 5050 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5051 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5052 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5053 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5054 | + subId + "' for key:" + key); |
| 5055 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5056 | } finally { |
| 5057 | Binder.restoreCallingIdentity(identity); |
| 5058 | } |
| 5059 | } |
| 5060 | |
| 5061 | @Override |
| 5062 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5063 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5064 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5065 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5066 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5067 | mApp, subId, "getImsProvisioningString"); |
| 5068 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
| 5071 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5072 | int slotId = getSlotIndex(subId); |
| 5073 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5074 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5075 | + subId + "' for key:" + key); |
| 5076 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5077 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5078 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5079 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5080 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5081 | + subId + "' for key:" + key); |
| 5082 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5083 | } finally { |
| 5084 | Binder.restoreCallingIdentity(identity); |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | @Override |
| 5089 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5090 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5091 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5092 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5094 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5095 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5096 | final long identity = Binder.clearCallingIdentity(); |
| 5097 | try { |
| 5098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5099 | int slotId = getSlotIndex(subId); |
| 5100 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5101 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5102 | + subId + "' for key:" + key); |
| 5103 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5104 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5105 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5106 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5107 | if (controller == null) { |
| 5108 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5109 | |
| 5110 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5111 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5112 | } |
| 5113 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5114 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5115 | return retVal; |
| 5116 | } |
| 5117 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5118 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5119 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5120 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5121 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5122 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5123 | } finally { |
| 5124 | Binder.restoreCallingIdentity(identity); |
| 5125 | } |
| 5126 | } |
| 5127 | |
| 5128 | @Override |
| 5129 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5130 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5131 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5132 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5134 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5135 | final long identity = Binder.clearCallingIdentity(); |
| 5136 | try { |
| 5137 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5138 | int slotId = getSlotIndex(subId); |
| 5139 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5140 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5141 | + subId + "' for key:" + key); |
| 5142 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5143 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5144 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5145 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5146 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5147 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5148 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5149 | } finally { |
| 5150 | Binder.restoreCallingIdentity(identity); |
| 5151 | } |
| 5152 | } |
| 5153 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5154 | /** |
| 5155 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5156 | * for the given slot ID or no ImsResolver instance has been created. |
| 5157 | * @param slotId The slot ID that the IMS service is created for. |
| 5158 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5159 | */ |
| 5160 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5161 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5162 | ImsFeature.FEATURE_MMTEL)) { |
| 5163 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5164 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5165 | } |
| 5166 | } |
| 5167 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5168 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5169 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5170 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5171 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5172 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5173 | } |
| 5174 | return slotId; |
| 5175 | } |
| 5176 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5177 | private int getSlotIndex(int subId) { |
| 5178 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5179 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5180 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5181 | } |
| 5182 | return slotId; |
| 5183 | } |
| 5184 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5185 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5186 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5187 | */ |
| 5188 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5189 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5190 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5191 | try { |
| 5192 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5193 | } catch (SecurityException se) { |
| 5194 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5195 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5196 | + Binder.getCallingUid()); |
| 5197 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5198 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5199 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5200 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5201 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5202 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5203 | mApp, subId, callingPackage, callingFeatureId, |
| 5204 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5205 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5206 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5207 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | final long identity = Binder.clearCallingIdentity(); |
| 5209 | try { |
| 5210 | final Phone phone = getPhone(subId); |
| 5211 | if (phone != null) { |
| 5212 | return phone.getServiceState().getDataNetworkType(); |
| 5213 | } else { |
| 5214 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5215 | } |
| 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5218 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | /** |
| 5222 | * Returns the data network type |
| 5223 | */ |
| 5224 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5225 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5226 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5227 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | /** |
| 5231 | * Returns the data network type for a subId |
| 5232 | */ |
| 5233 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5234 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5235 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5236 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5237 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5238 | mApp, functionName)) { |
| 5239 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5240 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5241 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5242 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5243 | } |
| 5244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5245 | final long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
| 5247 | final Phone phone = getPhone(subId); |
| 5248 | if (phone != null) { |
| 5249 | return phone.getServiceState().getDataNetworkType(); |
| 5250 | } else { |
| 5251 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5252 | } |
| 5253 | } finally { |
| 5254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5259 | * Returns the Voice network type for a subId |
| 5260 | */ |
| 5261 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5262 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5263 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5264 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5265 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5266 | mApp, functionName)) { |
| 5267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5268 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5269 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5270 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5271 | } |
| 5272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5273 | final long identity = Binder.clearCallingIdentity(); |
| 5274 | try { |
| 5275 | final Phone phone = getPhone(subId); |
| 5276 | if (phone != null) { |
| 5277 | return phone.getServiceState().getVoiceNetworkType(); |
| 5278 | } else { |
| 5279 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5280 | } |
| 5281 | } finally { |
| 5282 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | /** |
| 5287 | * @return true if a ICC card is present |
| 5288 | */ |
| 5289 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5290 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5291 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5292 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5296 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5297 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5298 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5299 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | final long identity = Binder.clearCallingIdentity(); |
| 5301 | try { |
| 5302 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5303 | if (phone != null) { |
| 5304 | return phone.getIccCard().hasIccCard(); |
| 5305 | } else { |
| 5306 | return false; |
| 5307 | } |
| 5308 | } finally { |
| 5309 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5310 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | /** |
| 5314 | * Return if the current radio is LTE on CDMA. This |
| 5315 | * is a tri-state return value as for a period of time |
| 5316 | * the mode may be unknown. |
| 5317 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5318 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5319 | * @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] | 5320 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5321 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5322 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5323 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5324 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5325 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5326 | } |
| 5327 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5328 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5329 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5330 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5331 | try { |
| 5332 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5333 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5334 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5335 | } |
| 5336 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | final long identity = Binder.clearCallingIdentity(); |
| 5338 | try { |
| 5339 | final Phone phone = getPhone(subId); |
| 5340 | if (phone == null) { |
| 5341 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5342 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5343 | return TelephonyProperties.lte_on_cdma_device() |
| 5344 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | } |
| 5346 | } finally { |
| 5347 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5348 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5351 | /** |
| 5352 | * {@hide} |
| 5353 | * Returns Default subId, 0 in the case of single standby. |
| 5354 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5355 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5356 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5359 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5360 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5363 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5364 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5365 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5366 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5367 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5368 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5369 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5370 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5371 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5372 | return mSubscriptionController.isActiveSubId(subId); |
| 5373 | } |
| 5374 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5375 | /** |
| 5376 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5377 | */ |
| 5378 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5381 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5383 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5384 | } finally { |
| 5385 | Binder.restoreCallingIdentity(identity); |
| 5386 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | /** |
| 5390 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5391 | */ |
| 5392 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5393 | final long identity = Binder.clearCallingIdentity(); |
| 5394 | try { |
| 5395 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5396 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5397 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5398 | } finally { |
| 5399 | Binder.restoreCallingIdentity(identity); |
| 5400 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5401 | } |
| 5402 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5403 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5404 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5405 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5406 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5407 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5408 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5409 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5410 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5411 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5412 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5413 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5414 | } |
| 5415 | return PhoneFactory.getPhone(phoneId); |
| 5416 | } |
| 5417 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5418 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5419 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5420 | @NonNull IccLogicalChannelRequest request) { |
| 5421 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5422 | /*message=*/ "iccOpenLogicalChannel"); |
| 5423 | |
| 5424 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5425 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5426 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5427 | |
| 5428 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5429 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5430 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5431 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5432 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5433 | Phone phone; |
| 5434 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5435 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5436 | mApp, request.subId, message); |
| 5437 | phone = getPhoneFromSubId(request.subId); |
| 5438 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5439 | enforceModifyPermission(); |
| 5440 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5441 | } else { |
| 5442 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5443 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5444 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5448 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | final long identity = Binder.clearCallingIdentity(); |
| 5450 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5451 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5452 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5453 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5454 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5455 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5456 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | loge("The calling package is not allowed to access ISD-R."); |
| 5458 | throw new SecurityException( |
| 5459 | "The calling package is not allowed to access ISD-R."); |
| 5460 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5461 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5462 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5463 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5464 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5465 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | return response; |
| 5467 | } finally { |
| 5468 | Binder.restoreCallingIdentity(identity); |
| 5469 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5473 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5474 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5475 | /*message=*/"iccCloseLogicalChannel"); |
| 5476 | |
| 5477 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5478 | |
| 5479 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5480 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5481 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5482 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5483 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5484 | // before this feature is enabled, this API should only return false if |
| 5485 | // the operation fails instead of throwing runtime exception for |
| 5486 | // backward-compatibility. |
| 5487 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5488 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5491 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5492 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5493 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5494 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5495 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5496 | Boolean success = false; |
| 5497 | if (result instanceof RuntimeException) { |
| 5498 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5499 | if (shouldThrowExceptionOnFailure) { |
| 5500 | throw (RuntimeException) result; |
| 5501 | } else { |
| 5502 | return false; |
| 5503 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5504 | } else if (result instanceof Boolean) { |
| 5505 | success = (Boolean) result; |
| 5506 | } else { |
| 5507 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5508 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5509 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5510 | return success; |
| 5511 | } finally { |
| 5512 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5513 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5517 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5518 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5520 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5521 | if (DBG) { |
| 5522 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5523 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5524 | + p3 + " data=" + data); |
| 5525 | } |
| 5526 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5527 | command, p1, p2, p3, data); |
| 5528 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5529 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5530 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5531 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5532 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5533 | enforceModifyPermission(); |
| 5534 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5535 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5536 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5537 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5538 | } |
| 5539 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5540 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5541 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5545 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | final long identity = Binder.clearCallingIdentity(); |
| 5547 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5548 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5549 | return ""; |
| 5550 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5551 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5553 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5554 | null /* workSource */); |
| 5555 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | // Append the returned status code to the end of the response payload. |
| 5558 | String s = Integer.toHexString( |
| 5559 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5560 | if (response.payload != null) { |
| 5561 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5562 | } |
| 5563 | return s; |
| 5564 | } finally { |
| 5565 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5566 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5567 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5568 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5569 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5570 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5571 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5573 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5575 | if (DBG) { |
| 5576 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5577 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5578 | } |
| 5579 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5580 | cla, command, p1, p2, p3, data); |
| 5581 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5582 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5583 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5584 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5585 | 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] | 5586 | enforceModifyPermission(); |
| 5587 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5588 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5589 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5590 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5591 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5595 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5596 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5600 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5601 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | final long identity = Binder.clearCallingIdentity(); |
| 5603 | try { |
| 5604 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5605 | && TextUtils.equals(ISDR_AID, data)) { |
| 5606 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5607 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5608 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | if (bestComponent == null |
| 5610 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5611 | loge("The calling package is not allowed to select ISD-R."); |
| 5612 | throw new SecurityException( |
| 5613 | "The calling package is not allowed to select ISD-R."); |
| 5614 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5615 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5618 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5619 | null /* workSource */); |
| 5620 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5622 | // Append the returned status code to the end of the response payload. |
| 5623 | String s = Integer.toHexString( |
| 5624 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5625 | if (response.payload != null) { |
| 5626 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5627 | } |
| 5628 | return s; |
| 5629 | } finally { |
| 5630 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5631 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5635 | 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] | 5636 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5638 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5639 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | if (DBG) { |
| 5643 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5644 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5645 | } |
| 5646 | |
| 5647 | IccIoResult response = |
| 5648 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5649 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5650 | subId); |
| 5651 | |
| 5652 | if (DBG) { |
| 5653 | log("Exchange SIM_IO [R]" + response); |
| 5654 | } |
| 5655 | |
| 5656 | byte[] result = null; |
| 5657 | int length = 2; |
| 5658 | if (response.payload != null) { |
| 5659 | length = 2 + response.payload.length; |
| 5660 | result = new byte[length]; |
| 5661 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5662 | } else { |
| 5663 | result = new byte[length]; |
| 5664 | } |
| 5665 | |
| 5666 | result[length - 1] = (byte) response.sw2; |
| 5667 | result[length - 2] = (byte) response.sw1; |
| 5668 | return result; |
| 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5671 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5672 | } |
| 5673 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5674 | /** |
| 5675 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5676 | * on a particular subscription |
| 5677 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5678 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5679 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5680 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5681 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5682 | return null; |
| 5683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5684 | |
| 5685 | final long identity = Binder.clearCallingIdentity(); |
| 5686 | try { |
| 5687 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5688 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5689 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5690 | return null; |
| 5691 | } |
| 5692 | Object response = sendRequest( |
| 5693 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5694 | if (response instanceof String[]) { |
| 5695 | return (String[]) response; |
| 5696 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5697 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5699 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5702 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5703 | } |
| 5704 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5705 | /** |
| 5706 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5707 | * subscription. |
| 5708 | * |
| 5709 | * @param subId the id of the subscription. |
| 5710 | * @param appType the uicc app type, must be USIM or SIM. |
| 5711 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5712 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5713 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5714 | * @return number of fplmns that is successfully written to the SIM. |
| 5715 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5716 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5717 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5719 | mApp, subId, "setForbiddenPlmns"); |
| 5720 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5721 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5722 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5723 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5724 | } |
| 5725 | if (fplmns == null) { |
| 5726 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5727 | } |
| 5728 | for (String fplmn : fplmns) { |
| 5729 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5730 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5731 | } |
| 5732 | } |
| 5733 | final long identity = Binder.clearCallingIdentity(); |
| 5734 | try { |
| 5735 | Object response = sendRequest( |
| 5736 | CMD_SET_FORBIDDEN_PLMNS, |
| 5737 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5738 | subId); |
| 5739 | return (int) response; |
| 5740 | } finally { |
| 5741 | Binder.restoreCallingIdentity(identity); |
| 5742 | } |
| 5743 | } |
| 5744 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5745 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5746 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5748 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5750 | final long identity = Binder.clearCallingIdentity(); |
| 5751 | try { |
| 5752 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5753 | if (response.payload == null) { |
| 5754 | return ""; |
| 5755 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | // Append the returned status code to the end of the response payload. |
| 5758 | String s = Integer.toHexString( |
| 5759 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5760 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5761 | return s; |
| 5762 | } finally { |
| 5763 | Binder.restoreCallingIdentity(identity); |
| 5764 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5767 | /** |
| 5768 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5769 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5770 | * |
| 5771 | * @param itemID the ID of the item to read |
| 5772 | * @return the NV item as a String, or null on error. |
| 5773 | */ |
| 5774 | @Override |
| 5775 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5776 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5777 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5778 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5779 | |
| 5780 | final long identity = Binder.clearCallingIdentity(); |
| 5781 | try { |
| 5782 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5783 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5785 | return value; |
| 5786 | } finally { |
| 5787 | Binder.restoreCallingIdentity(identity); |
| 5788 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | /** |
| 5792 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5793 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5794 | * |
| 5795 | * @param itemID the ID of the item to read |
| 5796 | * @param itemValue the value to write, as a String |
| 5797 | * @return true on success; false on any failure |
| 5798 | */ |
| 5799 | @Override |
| 5800 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5801 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5802 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5803 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5804 | |
| 5805 | final long identity = Binder.clearCallingIdentity(); |
| 5806 | try { |
| 5807 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5808 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5809 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5810 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5811 | return success; |
| 5812 | } finally { |
| 5813 | Binder.restoreCallingIdentity(identity); |
| 5814 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | /** |
| 5818 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5819 | * Used for device configuration by some CDMA operators. |
| 5820 | * |
| 5821 | * @param preferredRoamingList byte array containing the new PRL |
| 5822 | * @return true on success; false on any failure |
| 5823 | */ |
| 5824 | @Override |
| 5825 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5826 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5827 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | |
| 5829 | final long identity = Binder.clearCallingIdentity(); |
| 5830 | try { |
| 5831 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5832 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5833 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5834 | return success; |
| 5835 | } finally { |
| 5836 | Binder.restoreCallingIdentity(identity); |
| 5837 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5841 | * 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] | 5842 | * Used for device configuration by some CDMA operators. |
| 5843 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5844 | * @param slotIndex - device slot. |
| 5845 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5846 | * @return true on success; false on any failure |
| 5847 | */ |
| 5848 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5849 | public boolean resetModemConfig(int slotIndex) { |
| 5850 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5851 | if (phone != null) { |
| 5852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5853 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5855 | final long identity = Binder.clearCallingIdentity(); |
| 5856 | try { |
| 5857 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5858 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5859 | return success; |
| 5860 | } finally { |
| 5861 | Binder.restoreCallingIdentity(identity); |
| 5862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5863 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5864 | return false; |
| 5865 | } |
| 5866 | |
| 5867 | /** |
| 5868 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5869 | * |
| 5870 | * @param slotIndex - device slot. |
| 5871 | * |
| 5872 | * @return true on success; false on any failure |
| 5873 | */ |
| 5874 | @Override |
| 5875 | public boolean rebootModem(int slotIndex) { |
| 5876 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5877 | if (phone != null) { |
| 5878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5879 | mApp, phone.getSubId(), "rebootModem"); |
| 5880 | |
| 5881 | final long identity = Binder.clearCallingIdentity(); |
| 5882 | try { |
| 5883 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5884 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5885 | return success; |
| 5886 | } finally { |
| 5887 | Binder.restoreCallingIdentity(identity); |
| 5888 | } |
| 5889 | } |
| 5890 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5891 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5892 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5893 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5894 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5895 | * {@link #disableIms(int)}. |
| 5896 | * @param slotIndex device slot. |
| 5897 | */ |
| 5898 | public void resetIms(int slotIndex) { |
| 5899 | enforceModifyPermission(); |
| 5900 | |
| 5901 | final long identity = Binder.clearCallingIdentity(); |
| 5902 | try { |
| 5903 | if (mImsResolver == null) { |
| 5904 | // may happen if the does not support IMS. |
| 5905 | return; |
| 5906 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5907 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5908 | } finally { |
| 5909 | Binder.restoreCallingIdentity(identity); |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5914 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5915 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5916 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5917 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5918 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
| 5921 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5922 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5923 | // may happen if the device does not support IMS. |
| 5924 | return; |
| 5925 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5926 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | } finally { |
| 5928 | Binder.restoreCallingIdentity(identity); |
| 5929 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5933 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5934 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5935 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5936 | public void disableIms(int slotId) { |
| 5937 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5938 | |
| 5939 | final long identity = Binder.clearCallingIdentity(); |
| 5940 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5941 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5942 | // may happen if the device does not support IMS. |
| 5943 | return; |
| 5944 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5945 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | } finally { |
| 5947 | Binder.restoreCallingIdentity(identity); |
| 5948 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5949 | } |
| 5950 | |
| 5951 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5952 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5953 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5954 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5955 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5956 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5957 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | |
| 5959 | final long identity = Binder.clearCallingIdentity(); |
| 5960 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5961 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5962 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5963 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5964 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5965 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | } finally { |
| 5967 | Binder.restoreCallingIdentity(identity); |
| 5968 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5969 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5970 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5971 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5972 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5973 | @Override |
| 5974 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5975 | enforceModifyPermission(); |
| 5976 | |
| 5977 | final long identity = Binder.clearCallingIdentity(); |
| 5978 | try { |
| 5979 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5980 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5981 | } finally { |
| 5982 | Binder.restoreCallingIdentity(identity); |
| 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5987 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5988 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5989 | */ |
| 5990 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5991 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | |
| 5993 | final long identity = Binder.clearCallingIdentity(); |
| 5994 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5995 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5996 | // may happen if the device does not support IMS. |
| 5997 | return null; |
| 5998 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5999 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | } finally { |
| 6001 | Binder.restoreCallingIdentity(identity); |
| 6002 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6003 | } |
| 6004 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6005 | /** |
| 6006 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6007 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6008 | */ |
| 6009 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6010 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | |
| 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6014 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6015 | // may happen if the device does not support IMS. |
| 6016 | return null; |
| 6017 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6018 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | } finally { |
| 6020 | Binder.restoreCallingIdentity(identity); |
| 6021 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6022 | } |
| 6023 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6024 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6025 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6026 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6027 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6028 | * @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] | 6029 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6030 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6031 | * @param packageName The name of the package that the current configuration will be replaced |
| 6032 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6033 | * @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] | 6034 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6035 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6036 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6037 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6039 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | final long identity = Binder.clearCallingIdentity(); |
| 6042 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6043 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6044 | // may happen if the device does not support IMS. |
| 6045 | return false; |
| 6046 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6047 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6048 | for (int featureType : featureTypes) { |
| 6049 | featureConfig.put(featureType, packageName); |
| 6050 | } |
| 6051 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6052 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
| 6055 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6059 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6060 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6061 | * |
| 6062 | * This should only be used for testing. |
| 6063 | * |
| 6064 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6065 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6066 | */ |
| 6067 | @Override |
| 6068 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6069 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6070 | "clearCarrierImsServiceOverride"); |
| 6071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6072 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6073 | |
| 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
| 6076 | if (mImsResolver == null) { |
| 6077 | // may happen if the device does not support IMS. |
| 6078 | return false; |
| 6079 | } |
| 6080 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6087 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6088 | * |
| 6089 | * @param slotId The slot that the ImsService is associated with. |
| 6090 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6091 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6092 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6093 | * @return the package name of the ImsService configuration. |
| 6094 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6095 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6096 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6097 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6098 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6099 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6100 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6101 | final long identity = Binder.clearCallingIdentity(); |
| 6102 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6103 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6104 | // may happen if the device does not support IMS. |
| 6105 | return ""; |
| 6106 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6107 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6108 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6109 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | } finally { |
| 6111 | Binder.restoreCallingIdentity(identity); |
| 6112 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6113 | } |
| 6114 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6115 | /** |
| 6116 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6117 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6118 | * @param callback A callback with an integer containing the |
| 6119 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6120 | */ |
| 6121 | @Override |
| 6122 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6123 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6124 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6125 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6126 | "IMS not available on device."); |
| 6127 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6128 | final long token = Binder.clearCallingIdentity(); |
| 6129 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6130 | int slotId = getSlotIndex(subId); |
| 6131 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6132 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6133 | + subId + "'"); |
| 6134 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6135 | } |
| 6136 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6137 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6138 | try { |
| 6139 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6140 | } catch (RemoteException e) { |
| 6141 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6142 | + "Ignore"); |
| 6143 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6144 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6145 | } catch (ImsException e) { |
| 6146 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6147 | } finally { |
| 6148 | Binder.restoreCallingIdentity(token); |
| 6149 | } |
| 6150 | } |
| 6151 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6152 | /** |
| 6153 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6154 | */ |
| 6155 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6156 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | |
| 6158 | final long identity = Binder.clearCallingIdentity(); |
| 6159 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6160 | // NOTE: Before S, this method only set the default phone. |
| 6161 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6162 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6163 | phone.setImsRegistrationState(registered); |
| 6164 | } |
| 6165 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | } finally { |
| 6167 | Binder.restoreCallingIdentity(identity); |
| 6168 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6172 | * Set the network selection mode to automatic. |
| 6173 | * |
| 6174 | */ |
| 6175 | @Override |
| 6176 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6178 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6179 | |
| 6180 | final long identity = Binder.clearCallingIdentity(); |
| 6181 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6182 | if (!isActiveSubscription(subId)) { |
| 6183 | return; |
| 6184 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6185 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6186 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6187 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | } finally { |
| 6189 | Binder.restoreCallingIdentity(identity); |
| 6190 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6191 | } |
| 6192 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6193 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6194 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6195 | * |
| 6196 | * @param subId the id of the subscription. |
| 6197 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6198 | * the operator to attach to. |
| 6199 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6200 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6201 | * normal network selection next time. |
| 6202 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6203 | */ |
| 6204 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6205 | public boolean setNetworkSelectionModeManual( |
| 6206 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6208 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6209 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6210 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6211 | if (!isActiveSubscription(subId)) { |
| 6212 | return false; |
| 6213 | } |
| 6214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6215 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6216 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6217 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6218 | if (DBG) { |
| 6219 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6220 | + " operator: " + operatorInfo); |
| 6221 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6222 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6223 | } finally { |
| 6224 | Binder.restoreCallingIdentity(identity); |
| 6225 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6226 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6227 | /** |
| 6228 | * Get the manual network selection |
| 6229 | * |
| 6230 | * @param subId the id of the subscription. |
| 6231 | * |
| 6232 | * @return the previously saved user selected PLMN |
| 6233 | */ |
| 6234 | @Override |
| 6235 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6236 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6237 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6238 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6239 | |
| 6240 | final long identity = Binder.clearCallingIdentity(); |
| 6241 | try { |
| 6242 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6243 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | final Phone phone = getPhone(subId); |
| 6247 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6248 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6249 | } |
| 6250 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6251 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6252 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6253 | } finally { |
| 6254 | Binder.restoreCallingIdentity(identity); |
| 6255 | } |
| 6256 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6257 | |
| 6258 | /** |
| 6259 | * Scans for available networks. |
| 6260 | */ |
| 6261 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6262 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6263 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6265 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6266 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6267 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6268 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6269 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6270 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6271 | .setCallingPid(Binder.getCallingPid()) |
| 6272 | .setCallingUid(Binder.getCallingUid()) |
| 6273 | .setMethod("getCellNetworkScanResults") |
| 6274 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6275 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6276 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6277 | .build()); |
| 6278 | switch (locationResult) { |
| 6279 | case DENIED_HARD: |
| 6280 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6281 | case DENIED_SOFT: |
| 6282 | return null; |
| 6283 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6285 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | try { |
| 6287 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6288 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | } finally { |
| 6291 | Binder.restoreCallingIdentity(identity); |
| 6292 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6296 | * Get the call forwarding info, given the call forwarding reason. |
| 6297 | */ |
| 6298 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6299 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6300 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6301 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6302 | long identity = Binder.clearCallingIdentity(); |
| 6303 | try { |
| 6304 | if (DBG) { |
| 6305 | log("getCallForwarding: subId " + subId |
| 6306 | + " callForwardingReason" + callForwardingReason); |
| 6307 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6308 | |
| 6309 | Phone phone = getPhone(subId); |
| 6310 | if (phone == null) { |
| 6311 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6312 | callback.onError( |
| 6313 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6314 | } catch (RemoteException e) { |
| 6315 | // ignore |
| 6316 | } |
| 6317 | return; |
| 6318 | } |
| 6319 | |
| 6320 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6321 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6322 | @Override |
| 6323 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6324 | try { |
| 6325 | callback.onCallForwardingInfoAvailable(info); |
| 6326 | } catch (RemoteException e) { |
| 6327 | // ignore |
| 6328 | } |
| 6329 | } |
| 6330 | |
| 6331 | @Override |
| 6332 | public void onError(int error) { |
| 6333 | try { |
| 6334 | callback.onError(error); |
| 6335 | } catch (RemoteException e) { |
| 6336 | // ignore |
| 6337 | } |
| 6338 | } |
| 6339 | }); |
| 6340 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6341 | } finally { |
| 6342 | Binder.restoreCallingIdentity(identity); |
| 6343 | } |
| 6344 | } |
| 6345 | |
| 6346 | /** |
| 6347 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6348 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6349 | */ |
| 6350 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6351 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6352 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6353 | enforceModifyPermission(); |
| 6354 | long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
| 6356 | if (DBG) { |
| 6357 | log("setCallForwarding: subId " + subId |
| 6358 | + " callForwardingInfo" + callForwardingInfo); |
| 6359 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6360 | |
| 6361 | Phone phone = getPhone(subId); |
| 6362 | if (phone == null) { |
| 6363 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6364 | callback.accept( |
| 6365 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6366 | } catch (RemoteException e) { |
| 6367 | // ignore |
| 6368 | } |
| 6369 | return; |
| 6370 | } |
| 6371 | |
| 6372 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6373 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6374 | |
| 6375 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6376 | } finally { |
| 6377 | Binder.restoreCallingIdentity(identity); |
| 6378 | } |
| 6379 | } |
| 6380 | |
| 6381 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6382 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6383 | */ |
| 6384 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6385 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6386 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6387 | long identity = Binder.clearCallingIdentity(); |
| 6388 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6389 | Phone phone = getPhone(subId); |
| 6390 | if (phone == null) { |
| 6391 | try { |
| 6392 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6393 | } catch (RemoteException e) { |
| 6394 | // ignore |
| 6395 | } |
| 6396 | return; |
| 6397 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6398 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6399 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6400 | boolean requireUssd = c.getBoolean( |
| 6401 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6402 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6403 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6404 | if (requireUssd) { |
| 6405 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6406 | getSubscriptionCarrierId(subId)); |
| 6407 | String newUssdCommand = ""; |
| 6408 | try { |
| 6409 | newUssdCommand = carrierXmlParser.getFeature( |
| 6410 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6411 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6412 | } catch (NullPointerException e) { |
| 6413 | loge("Failed to generate USSD number" + e); |
| 6414 | } |
| 6415 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6416 | mMainThreadHandler, callback, carrierXmlParser, |
| 6417 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6418 | final String ussdCommand = newUssdCommand; |
| 6419 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6420 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6421 | }); |
| 6422 | } else { |
| 6423 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6424 | callback::accept); |
| 6425 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6426 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6433 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6434 | */ |
| 6435 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6436 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6437 | enforceModifyPermission(); |
| 6438 | long identity = Binder.clearCallingIdentity(); |
| 6439 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6440 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6441 | |
| 6442 | Phone phone = getPhone(subId); |
| 6443 | if (phone == null) { |
| 6444 | try { |
| 6445 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6446 | } catch (RemoteException e) { |
| 6447 | // ignore |
| 6448 | } |
| 6449 | return; |
| 6450 | } |
| 6451 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6452 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6453 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6454 | boolean requireUssd = c.getBoolean( |
| 6455 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6456 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6457 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6458 | if (requireUssd) { |
| 6459 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6460 | getSubscriptionCarrierId(subId)); |
| 6461 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6462 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6463 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6464 | String newUssdCommand = ""; |
| 6465 | try { |
| 6466 | newUssdCommand = carrierXmlParser.getFeature( |
| 6467 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6468 | .makeCommand(ssAction, null); |
| 6469 | } catch (NullPointerException e) { |
| 6470 | loge("Failed to generate USSD number" + e); |
| 6471 | } |
| 6472 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6473 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6474 | final String ussdCommand = newUssdCommand; |
| 6475 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6476 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6477 | }); |
| 6478 | } else { |
| 6479 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6480 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6481 | |
| 6482 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6483 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6484 | } finally { |
| 6485 | Binder.restoreCallingIdentity(identity); |
| 6486 | } |
| 6487 | } |
| 6488 | |
| 6489 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6490 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6491 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6492 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6493 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6494 | * location related information which will be sent if the caller already possess |
| 6495 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6496 | * @param request contains the radio access networks with bands/channels to scan |
| 6497 | * @param messenger callback messenger for scan results or errors |
| 6498 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6499 | * @return the id of the requested scan which can be used to stop the scan. |
| 6500 | */ |
| 6501 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6502 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6503 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6504 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6506 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6507 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6508 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6509 | if (!renounceFineLocationAccess) { |
| 6510 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6511 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6512 | .setCallingPackage(callingPackage) |
| 6513 | .setCallingFeatureId(callingFeatureId) |
| 6514 | .setCallingPid(Binder.getCallingPid()) |
| 6515 | .setCallingUid(Binder.getCallingUid()) |
| 6516 | .setMethod("requestNetworkScan") |
| 6517 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6518 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6519 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6520 | .build()); |
| 6521 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6522 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6523 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6524 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6525 | if (e != null) { |
| 6526 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6527 | throw e; |
| 6528 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6529 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6530 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6531 | } |
| 6532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6533 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6534 | int callingUid = Binder.getCallingUid(); |
| 6535 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6536 | final long identity = Binder.clearCallingIdentity(); |
| 6537 | try { |
| 6538 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6539 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6540 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6544 | } |
| 6545 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6546 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6547 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6548 | boolean hasCarrierPriv; |
| 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
| 6551 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6552 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6553 | } finally { |
| 6554 | Binder.restoreCallingIdentity(identity); |
| 6555 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6556 | boolean hasNetworkScanPermission = |
| 6557 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6558 | == PERMISSION_GRANTED; |
| 6559 | |
| 6560 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6561 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6562 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6566 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6567 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6568 | return new SecurityException("Specific channels must not be" |
| 6569 | + " scanned without location access."); |
| 6570 | } |
| 6571 | } |
| 6572 | } |
| 6573 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6574 | return null; |
| 6575 | } |
| 6576 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6577 | /** |
| 6578 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6579 | * |
| 6580 | * @param subId id of the subscription |
| 6581 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6582 | */ |
| 6583 | @Override |
| 6584 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6586 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6587 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6588 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6591 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6592 | } finally { |
| 6593 | Binder.restoreCallingIdentity(identity); |
| 6594 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6595 | } |
| 6596 | |
| 6597 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6598 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6599 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6600 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6601 | */ |
| 6602 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6603 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6604 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6605 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6606 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | |
| 6608 | final long identity = Binder.clearCallingIdentity(); |
| 6609 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6610 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6611 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6612 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6613 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6614 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6615 | } finally { |
| 6616 | Binder.restoreCallingIdentity(identity); |
| 6617 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6618 | } |
| 6619 | |
| 6620 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6621 | * Get the allowed network types for certain reason. |
| 6622 | * |
| 6623 | * @param subId the id of the subscription. |
| 6624 | * @param reason the reason the allowed network type change is taking place |
| 6625 | * @return the allowed network types. |
| 6626 | */ |
| 6627 | @Override |
| 6628 | public long getAllowedNetworkTypesForReason(int subId, |
| 6629 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6630 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6631 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
| 6634 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6635 | } finally { |
| 6636 | Binder.restoreCallingIdentity(identity); |
| 6637 | } |
| 6638 | } |
| 6639 | |
| 6640 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6641 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6642 | * @param subId subscription id of the sim card |
| 6643 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6644 | * This can be passed following states |
| 6645 | * <ol> |
| 6646 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6647 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6648 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6649 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6650 | * </ol> |
| 6651 | * @return operation result. |
| 6652 | */ |
| 6653 | @Override |
| 6654 | public int setNrDualConnectivityState(int subId, |
| 6655 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6657 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6658 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6659 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6660 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6661 | } |
| 6662 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6663 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6664 | final long identity = Binder.clearCallingIdentity(); |
| 6665 | try { |
| 6666 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6667 | nrDualConnectivityState, subId, |
| 6668 | workSource); |
| 6669 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6670 | return result; |
| 6671 | } finally { |
| 6672 | Binder.restoreCallingIdentity(identity); |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | /** |
| 6677 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6678 | * @return true if dual connectivity is enabled else false |
| 6679 | */ |
| 6680 | @Override |
| 6681 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6682 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6683 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6684 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6685 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6686 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6687 | return false; |
| 6688 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6689 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6690 | final long identity = Binder.clearCallingIdentity(); |
| 6691 | try { |
| 6692 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6693 | null, subId, workSource); |
| 6694 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6695 | return isEnabled; |
| 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(identity); |
| 6698 | } |
| 6699 | } |
| 6700 | |
| 6701 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6702 | * Set the allowed network types of the device and |
| 6703 | * provide the reason triggering the allowed network change. |
| 6704 | * |
| 6705 | * @param subId the id of the subscription. |
| 6706 | * @param reason the reason the allowed network type change is taking place |
| 6707 | * @param allowedNetworkTypes the allowed network types. |
| 6708 | * @return true on success; false on any failure. |
| 6709 | */ |
| 6710 | @Override |
| 6711 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6712 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6713 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6715 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6716 | // If the caller only has carrier privileges, then they should not be able to override |
| 6717 | // any network types which were set for security reasons. |
| 6718 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6719 | != PERMISSION_GRANTED |
| 6720 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6721 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6722 | throw new SecurityException( |
| 6723 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6724 | + " reason " |
| 6725 | + reason); |
| 6726 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6727 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6728 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6729 | return false; |
| 6730 | } |
| 6731 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6732 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6733 | return false; |
| 6734 | } |
| 6735 | |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 6736 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6737 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6738 | |
| 6739 | |
Aishwarya Mallampati | 32336e8 | 2023-01-04 23:02:56 +0000 | [diff] [blame] | 6740 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6741 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6742 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6743 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6744 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6745 | final long identity = Binder.clearCallingIdentity(); |
| 6746 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6747 | Boolean success = (Boolean) sendRequest( |
| 6748 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6749 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6750 | |
| 6751 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6752 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6753 | } finally { |
| 6754 | Binder.restoreCallingIdentity(identity); |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6759 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6760 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6761 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6762 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6763 | * @hide |
| 6764 | */ |
| 6765 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6766 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6767 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6768 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6769 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6771 | if (phone != null) { |
| 6772 | return phone.hasMatchedTetherApnSetting(); |
| 6773 | } else { |
| 6774 | return false; |
| 6775 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | } finally { |
| 6777 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6778 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6782 | * Get the user enabled state of Mobile Data. |
| 6783 | * |
| 6784 | * TODO: remove and use isUserDataEnabled. |
| 6785 | * This can't be removed now because some vendor codes |
| 6786 | * calls through ITelephony directly while they should |
| 6787 | * use TelephonyManager. |
| 6788 | * |
| 6789 | * @return true on enabled |
| 6790 | */ |
| 6791 | @Override |
| 6792 | public boolean getDataEnabled(int subId) { |
| 6793 | return isUserDataEnabled(subId); |
| 6794 | } |
| 6795 | |
| 6796 | /** |
| 6797 | * Get whether mobile data is enabled per user setting. |
| 6798 | * |
| 6799 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6800 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6801 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6802 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6803 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6804 | * |
| 6805 | * @return {@code true} if data is enabled else {@code false} |
| 6806 | */ |
| 6807 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6808 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6809 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6810 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6811 | try { |
| 6812 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6813 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6814 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6815 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6816 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6817 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6819 | mApp, subId, functionName); |
| 6820 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6821 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6822 | |
| 6823 | final long identity = Binder.clearCallingIdentity(); |
| 6824 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6825 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6827 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6828 | if (phone != null) { |
| 6829 | boolean retVal = phone.isUserDataEnabled(); |
| 6830 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6831 | return retVal; |
| 6832 | } else { |
| 6833 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6834 | return false; |
| 6835 | } |
| 6836 | } finally { |
| 6837 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6838 | } |
| 6839 | } |
| 6840 | |
| 6841 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6842 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6843 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6844 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6845 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6846 | * @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] | 6847 | */ |
| 6848 | @Override |
| 6849 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6850 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6851 | try { |
| 6852 | try { |
| 6853 | mApp.enforceCallingOrSelfPermission( |
| 6854 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6855 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6856 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6857 | try { |
| 6858 | mApp.enforceCallingOrSelfPermission( |
| 6859 | android.Manifest.permission.READ_PHONE_STATE, |
| 6860 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6861 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6862 | mApp.enforceCallingOrSelfPermission( |
| 6863 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6864 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6865 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6866 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6867 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6868 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6869 | |
| 6870 | final long identity = Binder.clearCallingIdentity(); |
| 6871 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6872 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6873 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6874 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6875 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6876 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6877 | return retVal; |
| 6878 | } else { |
| 6879 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6880 | return false; |
| 6881 | } |
| 6882 | } finally { |
| 6883 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6884 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6885 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6886 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6887 | /** |
| 6888 | * Check if data is enabled for a specific reason |
| 6889 | * @param subId Subscription index |
| 6890 | * @param reason the reason the data enable change is taking place |
| 6891 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6892 | */ |
| 6893 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6894 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6895 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6896 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6897 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6898 | try { |
| 6899 | mApp.enforceCallingOrSelfPermission( |
| 6900 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6901 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6902 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6903 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6904 | functionName); |
| 6905 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6906 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6907 | try { |
| 6908 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6909 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6910 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6911 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6912 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6913 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6914 | } |
| 6915 | |
| 6916 | |
| 6917 | final long identity = Binder.clearCallingIdentity(); |
| 6918 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6919 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6920 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6921 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6922 | + " reason=" + reason); |
| 6923 | } |
| 6924 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6925 | if (phone != null) { |
| 6926 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6927 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6928 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6929 | return retVal; |
| 6930 | } else { |
| 6931 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6932 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6933 | + subId + " retVal=false"); |
| 6934 | } |
| 6935 | return false; |
| 6936 | } |
| 6937 | } finally { |
| 6938 | Binder.restoreCallingIdentity(identity); |
| 6939 | } |
| 6940 | } |
| 6941 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6942 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6943 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6944 | // No permission needed; this only lets the caller inspect their own status. |
| 6945 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6946 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6947 | |
| 6948 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6949 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6950 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6951 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6952 | } |
| 6953 | |
| 6954 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6955 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6956 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6957 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6958 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6959 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6960 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6961 | if (cpt == null) { |
| 6962 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6963 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6964 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6965 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6969 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6970 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6971 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6972 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6973 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6974 | Phone phone = getPhone(subId); |
| 6975 | if (phone == null) { |
| 6976 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6977 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6978 | } |
| 6979 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6980 | if (cpt == null) { |
| 6981 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6982 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6983 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6984 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6985 | } |
| 6986 | |
| 6987 | @Override |
| 6988 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6989 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6990 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6991 | } |
| 6992 | |
| 6993 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6994 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6995 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6996 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6997 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6998 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6999 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7000 | if (phone == null) { |
| 7001 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7002 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7003 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7004 | if (cpt == null) { |
| 7005 | continue; |
| 7006 | } |
| 7007 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7008 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7009 | break; |
| 7010 | } |
| 7011 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7012 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7013 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7014 | |
| 7015 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7016 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7017 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7018 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7019 | if (phone == null) { |
| 7020 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7021 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7022 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7023 | if (cpt == null) { |
| 7024 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7025 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7026 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7027 | } |
| 7028 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7029 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7030 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7031 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7032 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7033 | if (phone == null) { |
| 7034 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7035 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7036 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7037 | if (cpt == null) { |
| 7038 | return Collections.emptyList(); |
| 7039 | } |
| 7040 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7041 | } |
| 7042 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7043 | @Override |
| 7044 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7045 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7046 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7047 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7048 | try { |
| 7049 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7050 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7051 | } |
| 7052 | } finally { |
| 7053 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7054 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7055 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7056 | } |
| 7057 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7058 | @Override |
| 7059 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7060 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7061 | |
| 7062 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7063 | if (phone == null) { |
| 7064 | return null; |
| 7065 | } |
| 7066 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7067 | if (cpt == null) { |
| 7068 | return null; |
| 7069 | } |
| 7070 | return cpt.getCarrierServicePackageName(); |
| 7071 | } |
| 7072 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7073 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7074 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7075 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7076 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7077 | return null; |
| 7078 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7079 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7080 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7081 | return null; |
| 7082 | } |
| 7083 | return iccId; |
| 7084 | } |
| 7085 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7086 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7087 | public void setCallComposerStatus(int subId, int status) { |
| 7088 | enforceModifyPermission(); |
| 7089 | |
| 7090 | final long identity = Binder.clearCallingIdentity(); |
| 7091 | try { |
| 7092 | Phone phone = getPhone(subId); |
| 7093 | if (phone != null) { |
| 7094 | Phone defaultPhone = phone.getImsPhone(); |
| 7095 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7096 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7097 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7098 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7099 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7100 | } |
| 7101 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7102 | } catch (ImsException e) { |
| 7103 | throw new ServiceSpecificException(e.getCode()); |
| 7104 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7105 | Binder.restoreCallingIdentity(identity); |
| 7106 | } |
| 7107 | } |
| 7108 | |
| 7109 | @Override |
| 7110 | public int getCallComposerStatus(int subId) { |
| 7111 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7112 | |
| 7113 | final long identity = Binder.clearCallingIdentity(); |
| 7114 | try { |
| 7115 | Phone phone = getPhone(subId); |
| 7116 | if (phone != null) { |
| 7117 | Phone defaultPhone = phone.getImsPhone(); |
| 7118 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7119 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7120 | return imsPhone.getCallComposerStatus(); |
| 7121 | } |
| 7122 | } |
| 7123 | } finally { |
| 7124 | Binder.restoreCallingIdentity(identity); |
| 7125 | } |
| 7126 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7127 | } |
| 7128 | |
| 7129 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7130 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7131 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7132 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7133 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7135 | final long identity = Binder.clearCallingIdentity(); |
| 7136 | try { |
| 7137 | final String iccId = getIccId(subId); |
| 7138 | final Phone phone = getPhone(subId); |
| 7139 | if (phone == null) { |
| 7140 | return false; |
| 7141 | } |
| 7142 | final String subscriberId = phone.getSubscriberId(); |
| 7143 | |
| 7144 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7145 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | + subscriberId + " to " + number); |
| 7147 | } |
| 7148 | |
| 7149 | if (TextUtils.isEmpty(iccId)) { |
| 7150 | return false; |
| 7151 | } |
| 7152 | |
| 7153 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7154 | |
| 7155 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7156 | if (alphaTag == null) { |
| 7157 | editor.remove(alphaTagPrefKey); |
| 7158 | } else { |
| 7159 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7160 | } |
| 7161 | |
| 7162 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7163 | // track all merged IMSIs based on line number |
| 7164 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7165 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7166 | if (number == null) { |
| 7167 | editor.remove(numberPrefKey); |
| 7168 | editor.remove(subscriberPrefKey); |
| 7169 | } else { |
| 7170 | editor.putString(numberPrefKey, number); |
| 7171 | editor.putString(subscriberPrefKey, subscriberId); |
| 7172 | } |
| 7173 | |
| 7174 | editor.commit(); |
| 7175 | return true; |
| 7176 | } finally { |
| 7177 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7178 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7179 | } |
| 7180 | |
| 7181 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7182 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7183 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7184 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7185 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7186 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7187 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7188 | return null; |
| 7189 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7190 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7191 | final long identity = Binder.clearCallingIdentity(); |
| 7192 | try { |
| 7193 | String iccId = getIccId(subId); |
| 7194 | if (iccId != null) { |
| 7195 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7196 | if (DBG_MERGE) { |
| 7197 | log("getLine1NumberForDisplay returning " |
| 7198 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7199 | } |
| 7200 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7201 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7202 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7203 | return null; |
| 7204 | } finally { |
| 7205 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7206 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7210 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7211 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7212 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7213 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7214 | return null; |
| 7215 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7216 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7217 | final long identity = Binder.clearCallingIdentity(); |
| 7218 | try { |
| 7219 | String iccId = getIccId(subId); |
| 7220 | if (iccId != null) { |
| 7221 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7222 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7223 | } |
| 7224 | return null; |
| 7225 | } finally { |
| 7226 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7227 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7228 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7229 | |
| 7230 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7231 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7232 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7233 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7234 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7236 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7237 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7238 | return null; |
| 7239 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7240 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7241 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7242 | // the process, where TelephonyManager was instantiated. |
| 7243 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7244 | final long identity = Binder.clearCallingIdentity(); |
| 7245 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7246 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7247 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7248 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7249 | |
| 7250 | // Figure out what subscribers are currently active |
| 7251 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7252 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7253 | // Only consider subs which match the current subId |
| 7254 | // This logic can be simplified. See b/131189269 for progress. |
| 7255 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7256 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7257 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | |
| 7259 | // First pass, find a number override for an active subscriber |
| 7260 | String mergeNumber = null; |
| 7261 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7262 | for (String key : prefs.keySet()) { |
| 7263 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7264 | final String subscriberId = (String) prefs.get(key); |
| 7265 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7266 | final String iccId = key.substring( |
| 7267 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7268 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7269 | mergeNumber = (String) prefs.get(numberKey); |
| 7270 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7271 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | + " for active subscriber " + subscriberId); |
| 7273 | } |
| 7274 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7275 | break; |
| 7276 | } |
| 7277 | } |
| 7278 | } |
| 7279 | } |
| 7280 | |
| 7281 | // Shortcut when no active merged subscribers |
| 7282 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7283 | return null; |
| 7284 | } |
| 7285 | |
| 7286 | // Second pass, find all subscribers under that line override |
| 7287 | final ArraySet<String> result = new ArraySet<>(); |
| 7288 | for (String key : prefs.keySet()) { |
| 7289 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7290 | final String number = (String) prefs.get(key); |
| 7291 | if (mergeNumber.equals(number)) { |
| 7292 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7293 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7294 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7295 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7296 | result.add(subscriberId); |
| 7297 | } |
| 7298 | } |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7303 | Arrays.sort(resultArray); |
| 7304 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7305 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7306 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7307 | } |
| 7308 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7309 | } finally { |
| 7310 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7311 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7312 | } |
| 7313 | |
| 7314 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7315 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7316 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7317 | |
| 7318 | final long identity = Binder.clearCallingIdentity(); |
| 7319 | try { |
| 7320 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7321 | TelephonyManager.class); |
| 7322 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7323 | if (subscriberId == null) { |
| 7324 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7325 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7326 | + subId); |
| 7327 | } |
| 7328 | return null; |
| 7329 | } |
| 7330 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7331 | ParcelUuid groupUuid; |
| 7332 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7333 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7334 | .getSubscriptionInfo(subId); |
| 7335 | groupUuid = info.getGroupUuid(); |
| 7336 | } else { |
| 7337 | final SubscriptionInfo info = mSubscriptionController |
| 7338 | .getSubscriptionInfo(subId); |
| 7339 | groupUuid = info.getGroupUuid(); |
| 7340 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7341 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7342 | if (groupUuid == null) { |
| 7343 | return new String[]{subscriberId}; |
| 7344 | } |
| 7345 | |
| 7346 | // Get all subscriberIds from the group. |
| 7347 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7348 | List<SubscriptionInfo> groupInfos; |
| 7349 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7350 | groupInfos = SubscriptionManagerService.getInstance() |
| 7351 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7352 | mApp.getAttributionTag()); |
| 7353 | } else { |
| 7354 | groupInfos = mSubscriptionController |
| 7355 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7356 | mApp.getAttributionTag()); |
| 7357 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7358 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7359 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7360 | if (subscriberId != null) { |
| 7361 | mergedSubscriberIds.add(subscriberId); |
| 7362 | } |
| 7363 | } |
| 7364 | |
| 7365 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
| 7368 | |
| 7369 | } |
| 7370 | } |
| 7371 | |
| 7372 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7373 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7374 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7375 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7376 | |
| 7377 | final long identity = Binder.clearCallingIdentity(); |
| 7378 | try { |
| 7379 | final Phone phone = getPhone(subId); |
| 7380 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7381 | } finally { |
| 7382 | Binder.restoreCallingIdentity(identity); |
| 7383 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7384 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7385 | |
| 7386 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7387 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7388 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7389 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7390 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7391 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7392 | |
| 7393 | final long identity = Binder.clearCallingIdentity(); |
| 7394 | try { |
| 7395 | final Phone phone = getPhone(subId); |
| 7396 | if (phone == null) { |
| 7397 | return false; |
| 7398 | } |
| 7399 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7400 | cdmaNonRoamingList); |
| 7401 | } finally { |
| 7402 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7403 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7404 | } |
| 7405 | |
| 7406 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7407 | @Deprecated |
| 7408 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7409 | enforceModifyPermission(); |
| 7410 | |
| 7411 | int returnValue = 0; |
| 7412 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7413 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7414 | if(result.exception == null) { |
| 7415 | if (result.result != null) { |
| 7416 | byte[] responseData = (byte[])(result.result); |
| 7417 | if(responseData.length > oemResp.length) { |
| 7418 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7419 | responseData.length + "bytes. Buffer Size is " + |
| 7420 | oemResp.length + "bytes."); |
| 7421 | } |
| 7422 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7423 | returnValue = responseData.length; |
| 7424 | } |
| 7425 | } else { |
| 7426 | CommandException ex = (CommandException) result.exception; |
| 7427 | returnValue = ex.getCommandError().ordinal(); |
| 7428 | if(returnValue > 0) returnValue *= -1; |
| 7429 | } |
| 7430 | } catch (RuntimeException e) { |
| 7431 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7432 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7433 | if(returnValue > 0) returnValue *= -1; |
| 7434 | } |
| 7435 | |
| 7436 | return returnValue; |
| 7437 | } |
| 7438 | |
| 7439 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7440 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7441 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7442 | try { |
| 7443 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7444 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7445 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7446 | } catch (SecurityException e) { |
| 7447 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7448 | throw e; |
| 7449 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7450 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7451 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7452 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7453 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7454 | final long identity = Binder.clearCallingIdentity(); |
| 7455 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7456 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7457 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7458 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7459 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | } finally { |
| 7461 | Binder.restoreCallingIdentity(identity); |
| 7462 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7463 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7464 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7465 | |
| 7466 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7467 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7468 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7469 | try { |
| 7470 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7471 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7472 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7473 | } |
| 7474 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7475 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7476 | } |
| 7477 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7478 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7479 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7480 | throw new SecurityException("App must be the dialer role holder to" |
| 7481 | + " upload a call composer pic"); |
| 7482 | } |
| 7483 | |
| 7484 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7485 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7486 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7487 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7488 | boolean readUntilEnd = false; |
| 7489 | int totalBytesRead = 0; |
| 7490 | byte[] buffer = new byte[16 * 1024]; |
| 7491 | while (true) { |
| 7492 | int numRead; |
| 7493 | try { |
| 7494 | numRead = input.read(buffer); |
| 7495 | } catch (IOException e) { |
| 7496 | try { |
| 7497 | fd.checkError(); |
| 7498 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7499 | null); |
| 7500 | } catch (IOException e1) { |
| 7501 | // This means that the other side closed explicitly with an error. If this |
| 7502 | // happens, log and ignore. |
| 7503 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7504 | } |
| 7505 | break; |
| 7506 | } |
| 7507 | if (numRead == -1) { |
| 7508 | readUntilEnd = true; |
| 7509 | break; |
| 7510 | } |
| 7511 | totalBytesRead += numRead; |
| 7512 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7513 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7514 | try { |
| 7515 | input.close(); |
| 7516 | } catch (IOException e) { |
| 7517 | // ignore |
| 7518 | } |
| 7519 | break; |
| 7520 | } |
| 7521 | output.write(buffer, 0, numRead); |
| 7522 | } |
| 7523 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7524 | // close is above, where the picture size is too big. |
| 7525 | |
| 7526 | try { |
| 7527 | fd.checkError(); |
| 7528 | } catch (IOException e) { |
| 7529 | loge("Remote end for call composer closed with an error: " + e); |
| 7530 | return; |
| 7531 | } |
| 7532 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7533 | if (!readUntilEnd) { |
| 7534 | loge("Did not finish reading entire image; aborting"); |
| 7535 | return; |
| 7536 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7537 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7538 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7539 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7540 | new CallComposerPictureTransfer.Factory() {}, |
| 7541 | imageData, |
| 7542 | (result) -> { |
| 7543 | if (result.first != null) { |
| 7544 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7545 | Bundle outputResult = new Bundle(); |
| 7546 | outputResult.putParcelable( |
| 7547 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7548 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7549 | outputResult); |
| 7550 | } else { |
| 7551 | callback.send(result.second, null); |
| 7552 | } |
| 7553 | } |
| 7554 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7555 | }); |
| 7556 | } |
| 7557 | |
| 7558 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7559 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7560 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7561 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | |
| 7563 | final long identity = Binder.clearCallingIdentity(); |
| 7564 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7565 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7566 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
| 7569 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7570 | } |
| 7571 | |
| 7572 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7573 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7574 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7575 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7576 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7577 | return false; |
| 7578 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7579 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7580 | final long identity = Binder.clearCallingIdentity(); |
| 7581 | try { |
| 7582 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7583 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7584 | // In the long run, we may instead need to check if there exists a connection service |
| 7585 | // which can support video calling. |
| 7586 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7587 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7588 | return imsManager.isVtEnabledByPlatform() |
| 7589 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7590 | && imsManager.isVtEnabledByUser(); |
| 7591 | } finally { |
| 7592 | Binder.restoreCallingIdentity(identity); |
| 7593 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7594 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7595 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7596 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7597 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7598 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7600 | mApp, subId, callingPackage, callingFeatureId, |
| 7601 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7602 | return false; |
| 7603 | } |
| 7604 | |
| 7605 | final long identity = Binder.clearCallingIdentity(); |
| 7606 | try { |
| 7607 | CarrierConfigManager configManager = |
| 7608 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7609 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7610 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7611 | } finally { |
| 7612 | Binder.restoreCallingIdentity(identity); |
| 7613 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7617 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7619 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7620 | return false; |
| 7621 | } |
| 7622 | |
| 7623 | final long identity = Binder.clearCallingIdentity(); |
| 7624 | try { |
| 7625 | CarrierConfigManager configManager = |
| 7626 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7627 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7628 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7629 | } finally { |
| 7630 | Binder.restoreCallingIdentity(identity); |
| 7631 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7632 | } |
| 7633 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7634 | @Override |
| 7635 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7636 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7637 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | @Override |
| 7641 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | final long identity = Binder.clearCallingIdentity(); |
| 7643 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7644 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | } finally { |
| 7646 | Binder.restoreCallingIdentity(identity); |
| 7647 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7648 | } |
| 7649 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7650 | /** |
| 7651 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7652 | * support for the feature and device firmware support. |
| 7653 | * |
| 7654 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7655 | */ |
| 7656 | @Override |
| 7657 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7658 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7659 | final Phone phone = getPhone(subscriptionId); |
| 7660 | if (phone == null) { |
| 7661 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7662 | return false; |
| 7663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7664 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7665 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7667 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7668 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7669 | return isCarrierSupported && isDeviceSupported; |
| 7670 | } finally { |
| 7671 | Binder.restoreCallingIdentity(identity); |
| 7672 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7673 | } |
| 7674 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7675 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7676 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7677 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7678 | * 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] | 7679 | */ |
| 7680 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7681 | final long identity = Binder.clearCallingIdentity(); |
| 7682 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7683 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7684 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7685 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7686 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7687 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7688 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7689 | } finally { |
| 7690 | Binder.restoreCallingIdentity(identity); |
| 7691 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7694 | @Deprecated |
| 7695 | @Override |
| 7696 | public String getDeviceId(String callingPackage) { |
| 7697 | return getDeviceIdWithFeature(callingPackage, null); |
| 7698 | } |
| 7699 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7700 | /** |
| 7701 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7702 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7703 | * |
| 7704 | * <p>Requires Permission: |
| 7705 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7706 | */ |
| 7707 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7708 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7709 | try { |
| 7710 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7711 | } catch (SecurityException se) { |
| 7712 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7713 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7714 | + Binder.getCallingUid()); |
| 7715 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7716 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7717 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7718 | return null; |
| 7719 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7720 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7721 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7722 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7723 | return null; |
| 7724 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7725 | |
| 7726 | final long identity = Binder.clearCallingIdentity(); |
| 7727 | try { |
| 7728 | return phone.getDeviceId(); |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
| 7731 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7732 | } |
| 7733 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7734 | /** |
| 7735 | * {@hide} |
| 7736 | * Returns the IMS Registration Status on a particular subid |
| 7737 | * |
| 7738 | * @param subId |
| 7739 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7740 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7741 | Phone phone = getPhone(subId); |
| 7742 | if (phone != null) { |
| 7743 | return phone.isImsRegistered(); |
| 7744 | } else { |
| 7745 | return false; |
| 7746 | } |
| 7747 | } |
| 7748 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7749 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7750 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7751 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7752 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7753 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7754 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7755 | } |
| 7756 | final long identity = Binder.clearCallingIdentity(); |
| 7757 | try { |
| 7758 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7759 | } finally { |
| 7760 | Binder.restoreCallingIdentity(identity); |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7765 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7766 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7767 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7768 | mApp, |
| 7769 | subscriptionId, |
| 7770 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7771 | final long identity = Binder.clearCallingIdentity(); |
| 7772 | try { |
| 7773 | Phone phone = getPhone(subscriptionId); |
| 7774 | if (phone == null) { |
| 7775 | return null; |
| 7776 | } |
| 7777 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7778 | } finally { |
| 7779 | Binder.restoreCallingIdentity(identity); |
| 7780 | } |
| 7781 | } |
| 7782 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7783 | /** |
| 7784 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7785 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7786 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7787 | final long identity = Binder.clearCallingIdentity(); |
| 7788 | try { |
| 7789 | Phone phone = getPhone(subId); |
| 7790 | if (phone != null) { |
| 7791 | return phone.isWifiCallingEnabled(); |
| 7792 | } else { |
| 7793 | return false; |
| 7794 | } |
| 7795 | } finally { |
| 7796 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7797 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7798 | } |
| 7799 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7800 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7801 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7802 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7803 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7804 | final long identity = Binder.clearCallingIdentity(); |
| 7805 | try { |
| 7806 | Phone phone = getPhone(subId); |
| 7807 | if (phone != null) { |
| 7808 | return phone.isVideoEnabled(); |
| 7809 | } else { |
| 7810 | return false; |
| 7811 | } |
| 7812 | } finally { |
| 7813 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7814 | } |
| 7815 | } |
| 7816 | |
| 7817 | /** |
| 7818 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7819 | * defined in {@link ImsRegistrationImplBase}. |
| 7820 | */ |
| 7821 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | final long identity = Binder.clearCallingIdentity(); |
| 7823 | try { |
| 7824 | Phone phone = getPhone(subId); |
| 7825 | if (phone != null) { |
| 7826 | return phone.getImsRegistrationTech(); |
| 7827 | } else { |
| 7828 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7829 | } |
| 7830 | } finally { |
| 7831 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7832 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7835 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7836 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7837 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7838 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7839 | return; |
| 7840 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7841 | Phone defaultPhone = getDefaultPhone(); |
| 7842 | if (defaultPhone != null) { |
| 7843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7844 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7845 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7846 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7847 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7848 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7849 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7850 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7851 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7852 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7853 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7854 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7855 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7856 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7857 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7858 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7859 | // There has been issues when Sms raw table somehow stores orphan |
| 7860 | // fragments. They lead to garbled message when new fragments come |
| 7861 | // in and combined with those stale ones. In case this happens again, |
| 7862 | // user can reset all network settings which will clean up this table. |
| 7863 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7864 | // Clean up IMS settings as well here. |
| 7865 | int slotId = getSlotIndex(subId); |
| 7866 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7867 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7868 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7869 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7870 | if (defaultPhone == null) { |
| 7871 | return; |
| 7872 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7873 | // Erase modem config if erase modem on network setting is enabled. |
| 7874 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7875 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7876 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7877 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7878 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7879 | |
| 7880 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7883 | } |
| 7884 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7885 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7886 | @VisibleForTesting |
| 7887 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7888 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7889 | return; |
| 7890 | } |
| 7891 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7892 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7893 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7894 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7895 | "user=" + defaultNetworkType); |
| 7896 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7897 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7898 | defaultNetworkType, null); |
| 7899 | } |
| 7900 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7901 | private void cleanUpSmsRawTable(Context context) { |
| 7902 | ContentResolver resolver = context.getContentResolver(); |
| 7903 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7904 | resolver.delete(uri, null, null); |
| 7905 | } |
| 7906 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7907 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7908 | public String getSimLocaleForSubscriber(int subId) { |
| 7909 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7910 | final Phone phone = getPhone(subId); |
| 7911 | if (phone == null) { |
| 7912 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7913 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7914 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7915 | final long identity = Binder.clearCallingIdentity(); |
| 7916 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7917 | SubscriptionInfo info; |
| 7918 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7919 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7920 | phone.getContext().getOpPackageName(), |
| 7921 | phone.getContext().getAttributionTag()); |
| 7922 | if (info == null) { |
| 7923 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7924 | return null; |
| 7925 | } |
| 7926 | } else { |
| 7927 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7928 | phone.getContext().getOpPackageName(), |
| 7929 | phone.getContext().getAttributionTag()); |
| 7930 | if (info == null) { |
| 7931 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7932 | return null; |
| 7933 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7934 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7936 | // preferences (EF-PL and EF-LI)... |
| 7937 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7938 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7939 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7940 | if (localeFromDefaultSim != null) { |
| 7941 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7942 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7943 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7944 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7945 | } else { |
| 7946 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7947 | } |
| 7948 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7949 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7950 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7951 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7952 | // the SIM and carrier preferences does not include a country we add the country |
| 7953 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7954 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7956 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7957 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7958 | } |
| 7959 | |
| 7960 | if (DBG) log("No locale found - returning null"); |
| 7961 | return null; |
| 7962 | } finally { |
| 7963 | Binder.restoreCallingIdentity(identity); |
| 7964 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7965 | } |
| 7966 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7967 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7968 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7969 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7970 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7971 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7972 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7973 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7974 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7975 | return localeTag; |
| 7976 | } |
| 7977 | } |
| 7978 | return inputLocale.toLanguageTag(); |
| 7979 | } |
| 7980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7981 | /** |
| 7982 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7983 | */ |
| 7984 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7985 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7986 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7987 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 7988 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7989 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7990 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7991 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7992 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7993 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7994 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7995 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7996 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7997 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7998 | * representing the state of the modem. |
| 7999 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8000 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8001 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8002 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8003 | */ |
| 8004 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8005 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8006 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8007 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8008 | |
| 8009 | final long identity = Binder.clearCallingIdentity(); |
| 8010 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8011 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8012 | } finally { |
| 8013 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8014 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8015 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8016 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8017 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 8018 | // less than total activity duration. |
| 8019 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8020 | if (info == null) { |
| 8021 | return false; |
| 8022 | } |
| 8023 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8024 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 8025 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8026 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8027 | return (info.isValid() |
| 8028 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8029 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 8030 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8031 | && (totalTxTimeMs <= activityDurationMs)); |
| 8032 | } |
| 8033 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8034 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8035 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8036 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8037 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8038 | |
| 8039 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8040 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8041 | } |
| 8042 | |
| 8043 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8044 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8045 | rat, |
| 8046 | freq, |
| 8047 | info.getReceiveTimeMillis(rat, freq) |
| 8048 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8049 | } |
| 8050 | |
| 8051 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8052 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8053 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8054 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8055 | |
| 8056 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8057 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8058 | } |
| 8059 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8060 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8061 | rat, |
| 8062 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8063 | } |
| 8064 | |
| 8065 | /** |
| 8066 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8067 | * @param info recent ModemActivityInfo |
| 8068 | */ |
| 8069 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8070 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8071 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8072 | boolean matched; |
| 8073 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8074 | matched = false; |
| 8075 | int rat = info.getSpecificInfoRat(i); |
| 8076 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8077 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8078 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8079 | //if it already exists |
| 8080 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8081 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8082 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8083 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8084 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8085 | updateLastModemActivityInfo(info, rat, freq); |
| 8086 | matched = true; |
| 8087 | } |
| 8088 | } else { |
| 8089 | updateLastModemActivityInfo(info, rat); |
| 8090 | matched = true; |
| 8091 | } |
| 8092 | } |
| 8093 | } |
| 8094 | |
| 8095 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8096 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8097 | new ActivityStatsTechSpecificInfo( |
| 8098 | rat, |
| 8099 | freq, |
| 8100 | info.getTransmitTimeMillis(rat, freq), |
| 8101 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8102 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8103 | } |
| 8104 | } |
| 8105 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8106 | mLastModemActivitySpecificInfo = |
| 8107 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8108 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8109 | |
| 8110 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8111 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8112 | info.getSleepTimeMillis() |
| 8113 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8114 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8115 | info.getIdleTimeMillis() |
| 8116 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8117 | |
| 8118 | mLastModemActivityInfo = |
| 8119 | new ModemActivityInfo( |
| 8120 | mLastModemActivityInfo.getTimestampMillis(), |
| 8121 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8122 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8123 | mLastModemActivitySpecificInfo); |
| 8124 | } |
| 8125 | |
| 8126 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8127 | ActivityStatsTechSpecificInfo[] info) { |
| 8128 | int infoSize = info.length; |
| 8129 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8130 | for (int i = 0; i < infoSize; i++) { |
| 8131 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8132 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8133 | info[i].getTransmitTimeMillis(), |
| 8134 | (int) info[i].getReceiveTimeMillis()); |
| 8135 | } |
| 8136 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8137 | } |
| 8138 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8139 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8140 | * Returns the service state information on specified subscription. |
| 8141 | */ |
| 8142 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8143 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8144 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8145 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8146 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8147 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8148 | return null; |
| 8149 | } |
| 8150 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8151 | boolean hasFinePermission = false; |
| 8152 | boolean hasCoarsePermission = false; |
| 8153 | if (!renounceFineLocationAccess) { |
| 8154 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8155 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8156 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8157 | .setCallingPackage(callingPackage) |
| 8158 | .setCallingFeatureId(callingFeatureId) |
| 8159 | .setCallingPid(Binder.getCallingPid()) |
| 8160 | .setCallingUid(Binder.getCallingUid()) |
| 8161 | .setMethod("getServiceStateForSubscriber") |
| 8162 | .setLogAsInfo(true) |
| 8163 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8164 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8165 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8166 | .build()); |
| 8167 | hasFinePermission = |
| 8168 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8169 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8170 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8171 | if (!renounceCoarseLocationAccess) { |
| 8172 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8173 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8174 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8175 | .setCallingPackage(callingPackage) |
| 8176 | .setCallingFeatureId(callingFeatureId) |
| 8177 | .setCallingPid(Binder.getCallingPid()) |
| 8178 | .setCallingUid(Binder.getCallingUid()) |
| 8179 | .setMethod("getServiceStateForSubscriber") |
| 8180 | .setLogAsInfo(true) |
| 8181 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8182 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8183 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8184 | .build()); |
| 8185 | hasCoarsePermission = |
| 8186 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8187 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8188 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8189 | final Phone phone = getPhone(subId); |
| 8190 | if (phone == null) { |
| 8191 | return null; |
| 8192 | } |
| 8193 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8194 | final long identity = Binder.clearCallingIdentity(); |
| 8195 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8196 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8197 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8198 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8199 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8200 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8201 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8202 | .getSubscriptionInfoInternal(subId); |
| 8203 | if (subInfo == null || !subInfo.isActive()) { |
| 8204 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8205 | + "subId=" + subId); |
| 8206 | return null; |
| 8207 | } |
| 8208 | } else { |
| 8209 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8210 | callingFeatureId)) { |
| 8211 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8212 | + "subId=" + subId); |
| 8213 | return null; |
| 8214 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8215 | } |
| 8216 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8217 | ServiceState ss = phone.getServiceState(); |
| 8218 | |
| 8219 | // Scrub out the location info in ServiceState depending on what level of access |
| 8220 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8221 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8222 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8223 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | } finally { |
| 8225 | Binder.restoreCallingIdentity(identity); |
| 8226 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8227 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8228 | |
| 8229 | /** |
| 8230 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8231 | * |
| 8232 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8233 | * voicemail ringtone. |
| 8234 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8235 | * PhoneAccount. |
| 8236 | */ |
| 8237 | @Override |
| 8238 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8239 | final long identity = Binder.clearCallingIdentity(); |
| 8240 | try { |
| 8241 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8242 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8243 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8244 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8245 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8246 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8247 | } finally { |
| 8248 | Binder.restoreCallingIdentity(identity); |
| 8249 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8253 | * Sets the per-account voicemail ringtone. |
| 8254 | * |
| 8255 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8256 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8257 | * |
| 8258 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8259 | * voicemail ringtone. |
| 8260 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8261 | * PhoneAccount. |
| 8262 | */ |
| 8263 | @Override |
| 8264 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8265 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8266 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8267 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8268 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8269 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8271 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8272 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8273 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8274 | |
| 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
| 8277 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8278 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8279 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8280 | } |
| 8281 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8282 | } finally { |
| 8283 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8284 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8285 | } |
| 8286 | |
| 8287 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8288 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8289 | * |
| 8290 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8291 | * voicemail vibration setting. |
| 8292 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8293 | */ |
| 8294 | @Override |
| 8295 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | final long identity = Binder.clearCallingIdentity(); |
| 8297 | try { |
| 8298 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8299 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8300 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8302 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8303 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8304 | } finally { |
| 8305 | Binder.restoreCallingIdentity(identity); |
| 8306 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8307 | } |
| 8308 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8309 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8310 | * Sets the per-account voicemail vibration. |
| 8311 | * |
| 8312 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8313 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8314 | * |
| 8315 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8316 | * voicemail vibration setting. |
| 8317 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8318 | * specific PhoneAccount. |
| 8319 | */ |
| 8320 | @Override |
| 8321 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8322 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8323 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8324 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8325 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8326 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8327 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8328 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8329 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8330 | } |
| 8331 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | try { |
| 8334 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8335 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8336 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8337 | } |
| 8338 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8339 | } finally { |
| 8340 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8341 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8342 | } |
| 8343 | |
| 8344 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8345 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8346 | * |
| 8347 | * @throws SecurityException if the caller does not have the required permission |
| 8348 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8349 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8350 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8351 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8352 | } |
| 8353 | |
| 8354 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8355 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8356 | * permission. |
| 8357 | * |
| 8358 | * @throws SecurityException if the caller does not have the required permission |
| 8359 | */ |
| 8360 | private void enforceSendSmsPermission() { |
| 8361 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8362 | } |
| 8363 | |
| 8364 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8365 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8366 | * users permission. |
| 8367 | * |
| 8368 | * @throws SecurityException if the caller does not have the required permission |
| 8369 | */ |
| 8370 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8371 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8372 | } |
| 8373 | |
| 8374 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8375 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8376 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8377 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8378 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8379 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8380 | final long identity = Binder.clearCallingIdentity(); |
| 8381 | try { |
| 8382 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8383 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8384 | if (componentName == null) { |
| 8385 | throw new SecurityException( |
| 8386 | "Caller not current active visual voicemail package[null]"); |
| 8387 | } |
| 8388 | String vvmPackage = componentName.getPackageName(); |
| 8389 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8390 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | } |
| 8392 | } finally { |
| 8393 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8394 | } |
| 8395 | } |
| 8396 | |
| 8397 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8398 | * Return the application ID for the app type. |
| 8399 | * |
| 8400 | * @param subId the subscription ID that this request applies to. |
| 8401 | * @param appType the uicc app type. |
| 8402 | * @return Application ID for specificied app type, or null if no uicc. |
| 8403 | */ |
| 8404 | @Override |
| 8405 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8406 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8407 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8410 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8411 | if (phone == null) { |
| 8412 | return null; |
| 8413 | } |
| 8414 | String aid = null; |
| 8415 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8416 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8417 | .getApplicationByType(appType).getAid(); |
| 8418 | } catch (Exception e) { |
| 8419 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8420 | } |
| 8421 | return aid; |
| 8422 | } finally { |
| 8423 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8424 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8425 | } |
| 8426 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8427 | /** |
| 8428 | * Return the Electronic Serial Number. |
| 8429 | * |
| 8430 | * @param subId the subscription ID that this request applies to. |
| 8431 | * @return ESN or null if error. |
| 8432 | */ |
| 8433 | @Override |
| 8434 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8435 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8436 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8437 | |
| 8438 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8439 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8440 | if (phone == null) { |
| 8441 | return null; |
| 8442 | } |
| 8443 | String esn = null; |
| 8444 | try { |
| 8445 | esn = phone.getEsn(); |
| 8446 | } catch (Exception e) { |
| 8447 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8448 | } |
| 8449 | return esn; |
| 8450 | } finally { |
| 8451 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8452 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8453 | } |
| 8454 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8455 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8456 | * Return the Preferred Roaming List Version. |
| 8457 | * |
| 8458 | * @param subId the subscription ID that this request applies to. |
| 8459 | * @return PRLVersion or null if error. |
| 8460 | */ |
| 8461 | @Override |
| 8462 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8463 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8464 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8465 | |
| 8466 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8467 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8468 | if (phone == null) { |
| 8469 | return null; |
| 8470 | } |
| 8471 | String cdmaPrlVersion = null; |
| 8472 | try { |
| 8473 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8474 | } catch (Exception e) { |
| 8475 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8476 | } |
| 8477 | return cdmaPrlVersion; |
| 8478 | } finally { |
| 8479 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8480 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8481 | } |
| 8482 | |
| 8483 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8484 | * Get snapshot of Telephony histograms |
| 8485 | * @return List of Telephony histograms |
| 8486 | * @hide |
| 8487 | */ |
| 8488 | @Override |
| 8489 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8490 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8491 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8492 | |
| 8493 | final long identity = Binder.clearCallingIdentity(); |
| 8494 | try { |
| 8495 | return RIL.getTelephonyRILTimingHistograms(); |
| 8496 | } finally { |
| 8497 | Binder.restoreCallingIdentity(identity); |
| 8498 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8499 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8500 | |
| 8501 | /** |
| 8502 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8503 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8504 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8505 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8506 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8507 | * @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] | 8508 | */ |
| 8509 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8510 | @TelephonyManager.SetCarrierRestrictionResult |
| 8511 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8512 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8513 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8514 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8515 | if (carrierRestrictionRules == null) { |
| 8516 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8517 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8518 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8519 | final long identity = Binder.clearCallingIdentity(); |
| 8520 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8521 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8522 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8523 | } finally { |
| 8524 | Binder.restoreCallingIdentity(identity); |
| 8525 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
| 8528 | /** |
| 8529 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8530 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8531 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8532 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8533 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8534 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8535 | */ |
| 8536 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8537 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8538 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8539 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8540 | |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8543 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8544 | if (response instanceof CarrierRestrictionRules) { |
| 8545 | return (CarrierRestrictionRules) response; |
| 8546 | } |
| 8547 | // Response is an Exception of some kind, |
| 8548 | // which is signalled to the user as a NULL retval |
| 8549 | return null; |
| 8550 | } catch (Exception e) { |
| 8551 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8552 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8553 | } finally { |
| 8554 | Binder.restoreCallingIdentity(identity); |
| 8555 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8556 | } |
| 8557 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8558 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8559 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8560 | * @param subId the subscription ID that this action applies to. |
| 8561 | * @param enabled control enable or disable radio. |
| 8562 | * {@hide} |
| 8563 | */ |
| 8564 | @Override |
| 8565 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8566 | enforceModifyPermission(); |
| 8567 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8568 | |
| 8569 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8570 | if (phone == null) { |
| 8571 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8572 | return; |
| 8573 | } |
| 8574 | try { |
| 8575 | phone.carrierActionSetRadioEnabled(enabled); |
| 8576 | } catch (Exception e) { |
| 8577 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8578 | } finally { |
| 8579 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8580 | } |
| 8581 | } |
| 8582 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8583 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8584 | * Enable or disable Voice over NR (VoNR) |
| 8585 | * @param subId the subscription ID that this action applies to. |
| 8586 | * @param enabled enable or disable VoNR. |
| 8587 | * @return operation result. |
| 8588 | */ |
| 8589 | @Override |
| 8590 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8591 | enforceModifyPermission(); |
| 8592 | final Phone phone = getPhone(subId); |
| 8593 | |
| 8594 | final long identity = Binder.clearCallingIdentity(); |
| 8595 | if (phone == null) { |
| 8596 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8597 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8598 | } |
| 8599 | |
| 8600 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8601 | try { |
| 8602 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8603 | workSource); |
| 8604 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8605 | |
| 8606 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8607 | if (DBG) { |
| 8608 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8609 | } |
| 8610 | SubscriptionManager.setSubscriptionProperty( |
| 8611 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8612 | (enabled ? "1" : "0")); |
| 8613 | } |
| 8614 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8615 | return result; |
| 8616 | } finally { |
| 8617 | Binder.restoreCallingIdentity(identity); |
| 8618 | } |
| 8619 | } |
| 8620 | |
| 8621 | /** |
| 8622 | * Is voice over NR enabled |
| 8623 | * @return true if VoNR is enabled else false |
| 8624 | */ |
| 8625 | @Override |
| 8626 | public boolean isVoNrEnabled(int subId) { |
| 8627 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8628 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8629 | final long identity = Binder.clearCallingIdentity(); |
| 8630 | try { |
| 8631 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8632 | null, subId, workSource); |
| 8633 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8634 | return isEnabled; |
| 8635 | } finally { |
| 8636 | Binder.restoreCallingIdentity(identity); |
| 8637 | } |
| 8638 | } |
| 8639 | |
| 8640 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8641 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8642 | * network status based on which carrier apps could apply actions accordingly, |
| 8643 | * enable/disable default url handler for example. |
| 8644 | * |
| 8645 | * @param subId the subscription ID that this action applies to. |
| 8646 | * @param report control start/stop reporting the default network status. |
| 8647 | * {@hide} |
| 8648 | */ |
| 8649 | @Override |
| 8650 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8651 | enforceModifyPermission(); |
| 8652 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8653 | |
| 8654 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8655 | if (phone == null) { |
| 8656 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8657 | return; |
| 8658 | } |
| 8659 | try { |
| 8660 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8661 | } catch (Exception e) { |
| 8662 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8663 | } finally { |
| 8664 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8665 | } |
| 8666 | } |
| 8667 | |
| 8668 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8669 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8670 | * @param subId the subscription ID that this action applies to. |
| 8671 | * {@hide} |
| 8672 | */ |
| 8673 | @Override |
| 8674 | public void carrierActionResetAll(int subId) { |
| 8675 | enforceModifyPermission(); |
| 8676 | final Phone phone = getPhone(subId); |
| 8677 | if (phone == null) { |
| 8678 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8679 | return; |
| 8680 | } |
| 8681 | try { |
| 8682 | phone.carrierActionResetAll(); |
| 8683 | } catch (Exception e) { |
| 8684 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8685 | } |
| 8686 | } |
| 8687 | |
| 8688 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8689 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8690 | * bug report is being generated. |
| 8691 | */ |
| 8692 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8693 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8694 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8695 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8696 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8697 | + Binder.getCallingPid() |
| 8698 | + ", uid=" + Binder.getCallingUid() |
| 8699 | + "without permission " |
| 8700 | + android.Manifest.permission.DUMP); |
| 8701 | return; |
| 8702 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8703 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8704 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8705 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8706 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8707 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8708 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8709 | @NonNull String[] args) { |
| 8710 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8711 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8712 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8713 | } |
| 8714 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8715 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8716 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8717 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8718 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8719 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8720 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8721 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8722 | */ |
| 8723 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8724 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8725 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8726 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8727 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8728 | try { |
| 8729 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8730 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8731 | } catch (SecurityException se) { |
| 8732 | enforceModifyPermission(); |
| 8733 | } |
| 8734 | } else { |
| 8735 | enforceModifyPermission(); |
| 8736 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8737 | |
| 8738 | final long identity = Binder.clearCallingIdentity(); |
| 8739 | try { |
| 8740 | Phone phone = getPhone(subId); |
| 8741 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8742 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8743 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8744 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8745 | phone.getDataSettingsManager().setDataEnabled( |
| 8746 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8747 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8748 | } |
| 8749 | } finally { |
| 8750 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8751 | } |
| 8752 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8753 | |
| 8754 | /** |
| 8755 | * Get Client request stats |
| 8756 | * @return List of Client Request Stats |
| 8757 | * @hide |
| 8758 | */ |
| 8759 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8760 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8761 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8763 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8764 | return null; |
| 8765 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8766 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8768 | final long identity = Binder.clearCallingIdentity(); |
| 8769 | try { |
| 8770 | if (phone != null) { |
| 8771 | return phone.getClientRequestStats(); |
| 8772 | } |
| 8773 | |
| 8774 | return null; |
| 8775 | } finally { |
| 8776 | Binder.restoreCallingIdentity(identity); |
| 8777 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8778 | } |
| 8779 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8780 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8781 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8782 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8783 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8784 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8785 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8786 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8787 | // commands that plumb through the RIL as root, like so: |
| 8788 | // $ adb root |
| 8789 | // $ adb shell cmd phone ... |
| 8790 | packageName = "root"; |
| 8791 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8792 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8793 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8794 | |
| 8795 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8796 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8797 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8798 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8799 | * @param state State of SIM (power down, power up, pass through) |
| 8800 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8801 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8802 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8803 | * |
| 8804 | **/ |
| 8805 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8806 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8807 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8808 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8809 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8810 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8812 | final long identity = Binder.clearCallingIdentity(); |
| 8813 | try { |
| 8814 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8815 | phone.setSimPowerState(state, null, workSource); |
| 8816 | } |
| 8817 | } finally { |
| 8818 | Binder.restoreCallingIdentity(identity); |
| 8819 | } |
| 8820 | } |
| 8821 | |
| 8822 | /** |
| 8823 | * Set SIM card power state. |
| 8824 | * |
| 8825 | * @param slotIndex SIM slot id. |
| 8826 | * @param state State of SIM (power down, power up, pass through) |
| 8827 | * @param callback callback to trigger after success or failure |
| 8828 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8829 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8830 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8831 | * |
| 8832 | **/ |
| 8833 | @Override |
| 8834 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8835 | IIntegerConsumer callback) { |
| 8836 | enforceModifyPermission(); |
| 8837 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8838 | |
| 8839 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8840 | |
| 8841 | final long identity = Binder.clearCallingIdentity(); |
| 8842 | try { |
| 8843 | if (phone != null) { |
| 8844 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8845 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8846 | } |
| 8847 | } finally { |
| 8848 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8849 | } |
| 8850 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8851 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8852 | private boolean isUssdApiAllowed(int subId) { |
| 8853 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8854 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8855 | if (configManager == null) { |
| 8856 | return false; |
| 8857 | } |
| 8858 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8859 | if (pb == null) { |
| 8860 | return false; |
| 8861 | } |
| 8862 | return pb.getBoolean( |
| 8863 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8864 | } |
| 8865 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8866 | /** |
| 8867 | * Check if phone is in emergency callback mode |
| 8868 | * @return true if phone is in emergency callback mode |
| 8869 | * @param subId sub id |
| 8870 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8871 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8872 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8873 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8874 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8875 | |
| 8876 | final long identity = Binder.clearCallingIdentity(); |
| 8877 | try { |
| 8878 | if (phone != null) { |
| 8879 | return phone.isInEcm(); |
| 8880 | } else { |
| 8881 | return false; |
| 8882 | } |
| 8883 | } finally { |
| 8884 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8885 | } |
| 8886 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8887 | |
| 8888 | /** |
| 8889 | * Get the current signal strength information for the given subscription. |
| 8890 | * Because this information is not updated when the device is in a low power state |
| 8891 | * it should not be relied-upon to be current. |
| 8892 | * @param subId Subscription index |
| 8893 | * @return the most recent cached signal strength info from the modem |
| 8894 | */ |
| 8895 | @Override |
| 8896 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8897 | final long identity = Binder.clearCallingIdentity(); |
| 8898 | try { |
| 8899 | Phone p = getPhone(subId); |
| 8900 | if (p == null) { |
| 8901 | return null; |
| 8902 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8903 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8904 | return p.getSignalStrength(); |
| 8905 | } finally { |
| 8906 | Binder.restoreCallingIdentity(identity); |
| 8907 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8908 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8909 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8910 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8911 | * Get the current modem radio state for the given slot. |
| 8912 | * @param slotIndex slot index. |
| 8913 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8914 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8915 | * @return the current radio power state from the modem |
| 8916 | */ |
| 8917 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8918 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8919 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8920 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8921 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8922 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8923 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8924 | } |
| 8925 | |
| 8926 | final long identity = Binder.clearCallingIdentity(); |
| 8927 | try { |
| 8928 | return phone.getRadioPowerState(); |
| 8929 | } finally { |
| 8930 | Binder.restoreCallingIdentity(identity); |
| 8931 | } |
| 8932 | } |
| 8933 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8934 | } |
| 8935 | |
| 8936 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8937 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8938 | * |
| 8939 | * <p>Requires one of the following permissions: |
| 8940 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8941 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8942 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8943 | * privileges. |
| 8944 | * |
| 8945 | * @param subId subscription id |
| 8946 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8947 | * {@code false}. |
| 8948 | */ |
| 8949 | @Override |
| 8950 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8951 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8952 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8953 | try { |
| 8954 | mApp.enforceCallingOrSelfPermission( |
| 8955 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8956 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8957 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8958 | mApp.enforceCallingOrSelfPermission( |
| 8959 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8960 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8961 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8962 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8963 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8964 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8965 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8966 | boolean isEnabled = false; |
| 8967 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8968 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8969 | Phone phone = getPhone(subId); |
| 8970 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8971 | } finally { |
| 8972 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8973 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8974 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8975 | } |
| 8976 | |
| 8977 | |
| 8978 | /** |
| 8979 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8980 | * |
| 8981 | * <p> Requires permission: |
| 8982 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8983 | * privileges. |
| 8984 | * |
| 8985 | * @param subId subscription id |
| 8986 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8987 | */ |
| 8988 | @Override |
| 8989 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8990 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8991 | mApp, subId, "setDataRoamingEnabled"); |
| 8992 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8993 | final long identity = Binder.clearCallingIdentity(); |
| 8994 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8995 | Phone phone = getPhone(subId); |
| 8996 | if (phone != null) { |
| 8997 | phone.setDataRoamingEnabled(isEnabled); |
| 8998 | } |
| 8999 | } finally { |
| 9000 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9001 | } |
| 9002 | } |
| 9003 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9004 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9005 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9006 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9007 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9008 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 9009 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9010 | boolean isAllowed = true; |
| 9011 | final long identity = Binder.clearCallingIdentity(); |
| 9012 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9013 | Phone phone = getPhone(subId); |
| 9014 | if (phone != null) { |
| 9015 | isAllowed = phone.isCspPlmnEnabled(); |
| 9016 | } |
| 9017 | } finally { |
| 9018 | Binder.restoreCallingIdentity(identity); |
| 9019 | } |
| 9020 | return isAllowed; |
| 9021 | } |
| 9022 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9023 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9024 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9025 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9026 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9027 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9028 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9029 | if (phone == null) { |
| 9030 | return false; |
| 9031 | } |
| 9032 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9033 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9034 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9035 | } |
| 9036 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9037 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9038 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9039 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9040 | mApp.getSystemService(AppOpsManager.class) |
| 9041 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9042 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9043 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9044 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9045 | try { |
| 9046 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9047 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9048 | } catch (SecurityException e) { |
| 9049 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9050 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9051 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9052 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9053 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9054 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9055 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9056 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9057 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9058 | Binder.getCallingUid())) { |
| 9059 | isIccIdAccessRestricted = true; |
| 9060 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9061 | final long identity = Binder.clearCallingIdentity(); |
| 9062 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9063 | UiccController uiccController = UiccController.getInstance(); |
| 9064 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9065 | if (hasReadPermission) { |
| 9066 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9067 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9068 | |
| 9069 | // Remove private info if the caller doesn't have access |
| 9070 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9071 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9072 | //setting the value after compatibility check |
| 9073 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9074 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9075 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9076 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9077 | if (card == null) { |
| 9078 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9079 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9080 | continue; |
| 9081 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9082 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9083 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9084 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9085 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9086 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9087 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9088 | for (UiccPortInfo portInfo : portInfos) { |
| 9089 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9090 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9091 | if (port == null) { |
| 9092 | // assume no access if port is null |
| 9093 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9094 | continue; |
| 9095 | } |
| 9096 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9097 | uiccPortInfos.add(portInfo); |
| 9098 | } else { |
| 9099 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9100 | } |
| 9101 | } |
| 9102 | filteredInfos.add(new UiccCardInfo( |
| 9103 | cardInfo.isEuicc(), |
| 9104 | cardInfo.getCardId(), |
| 9105 | null, |
| 9106 | cardInfo.getPhysicalSlotIndex(), |
| 9107 | cardInfo.isRemovable(), |
| 9108 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9109 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9110 | } |
| 9111 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9112 | } finally { |
| 9113 | Binder.restoreCallingIdentity(identity); |
| 9114 | } |
| 9115 | } |
| 9116 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9117 | /** |
| 9118 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9119 | * generally private and require carrier privileges to view. |
| 9120 | * |
| 9121 | * @hide |
| 9122 | */ |
| 9123 | @NonNull |
| 9124 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9125 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9126 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9127 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9128 | } |
| 9129 | return new UiccCardInfo( |
| 9130 | cardInfo.isEuicc(), |
| 9131 | cardInfo.getCardId(), |
| 9132 | null, |
| 9133 | cardInfo.getPhysicalSlotIndex(), |
| 9134 | cardInfo.isRemovable(), |
| 9135 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9136 | portinfo |
| 9137 | ); |
| 9138 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9139 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9140 | /** |
| 9141 | * @hide |
| 9142 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9143 | * These values are generally private and require carrier privileges to view. |
| 9144 | */ |
| 9145 | @NonNull |
| 9146 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9147 | return new UiccPortInfo( |
| 9148 | UiccPortInfo.ICCID_REDACTED, |
| 9149 | portInfo.getPortIndex(), |
| 9150 | portInfo.getLogicalSlotIndex(), |
| 9151 | portInfo.isActive() |
| 9152 | ); |
| 9153 | } |
| 9154 | @Override |
| 9155 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9156 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9157 | mApp.getSystemService(AppOpsManager.class) |
| 9158 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9159 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9160 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9161 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9162 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9163 | // we are reading iccId which is PII data. |
| 9164 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9165 | |
| 9166 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9167 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9168 | Binder.getCallingUid())) { |
| 9169 | isLogicalSlotAccessRestricted = true; |
| 9170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9171 | final long identity = Binder.clearCallingIdentity(); |
| 9172 | try { |
| 9173 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9174 | if (slots == null || slots.length == 0) { |
| 9175 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9176 | return null; |
| 9177 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9178 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9179 | for (int i = 0; i < slots.length; i++) { |
| 9180 | UiccSlot slot = slots[i]; |
| 9181 | if (slot == null) { |
| 9182 | continue; |
| 9183 | } |
| 9184 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9185 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9186 | UiccCard card = slot.getUiccCard(); |
| 9187 | if (card != null) { |
| 9188 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9189 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9190 | cardId = slot.getEid(); |
| 9191 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9192 | // If cardId is null, use iccId of default port as cardId. |
| 9193 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9194 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9195 | } |
| 9196 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9197 | if (cardId != null) { |
| 9198 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9199 | // if cardId is an EID, it's all digits so this is fine |
| 9200 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9201 | } |
| 9202 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9203 | int cardState = 0; |
| 9204 | switch (slot.getCardState()) { |
| 9205 | case CARDSTATE_ABSENT: |
| 9206 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9207 | break; |
| 9208 | case CARDSTATE_PRESENT: |
| 9209 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9210 | break; |
| 9211 | case CARDSTATE_ERROR: |
| 9212 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9213 | break; |
| 9214 | case CARDSTATE_RESTRICTED: |
| 9215 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9216 | break; |
| 9217 | default: |
| 9218 | break; |
| 9219 | |
| 9220 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9221 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9222 | int[] portIndexes = slot.getPortList(); |
| 9223 | for (int portIdx : portIndexes) { |
| 9224 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9225 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9226 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9227 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9228 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9229 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9230 | slot.isEuicc(), |
| 9231 | cardId, |
| 9232 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9233 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9234 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9235 | //setting the value after compatibility check |
| 9236 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9237 | } |
| 9238 | return infos; |
| 9239 | } finally { |
| 9240 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9241 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9242 | } |
| 9243 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9244 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9245 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9246 | boolean hasReadPermission) { |
| 9247 | String iccId = slot.getIccId(portIndex); |
| 9248 | if (hasReadPermission) { // if has read permission |
| 9249 | return iccId; |
| 9250 | } else { |
| 9251 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9252 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9253 | // if no read permission, checking carrier privilege access |
| 9254 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9255 | return iccId; |
| 9256 | } |
| 9257 | } |
| 9258 | } |
| 9259 | // No read permission or carrier privilege access. |
| 9260 | return UiccPortInfo.ICCID_REDACTED; |
| 9261 | } |
| 9262 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9263 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9264 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9265 | public boolean switchSlots(int[] physicalSlots) { |
| 9266 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9267 | |
| 9268 | final long identity = Binder.clearCallingIdentity(); |
| 9269 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9270 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9271 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9272 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9273 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9274 | physicalSlots[i], i)); |
| 9275 | } |
| 9276 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9277 | } finally { |
| 9278 | Binder.restoreCallingIdentity(identity); |
| 9279 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9280 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9281 | |
| 9282 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9283 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9284 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9285 | enforceModifyPermission(); |
| 9286 | |
| 9287 | final long identity = Binder.clearCallingIdentity(); |
| 9288 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9289 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9290 | } finally { |
| 9291 | Binder.restoreCallingIdentity(identity); |
| 9292 | } |
| 9293 | } |
| 9294 | |
| 9295 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9296 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9297 | final long identity = Binder.clearCallingIdentity(); |
| 9298 | try { |
| 9299 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9300 | } finally { |
| 9301 | Binder.restoreCallingIdentity(identity); |
| 9302 | } |
| 9303 | } |
| 9304 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9305 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9306 | * A test API to reload the UICC profile. |
| 9307 | * |
| 9308 | * <p>Requires that the calling app has permission |
| 9309 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9310 | * @hide |
| 9311 | */ |
| 9312 | @Override |
| 9313 | public void refreshUiccProfile(int subId) { |
| 9314 | enforceModifyPermission(); |
| 9315 | |
| 9316 | final long identity = Binder.clearCallingIdentity(); |
| 9317 | try { |
| 9318 | Phone phone = getPhone(subId); |
| 9319 | if (phone == null) { |
| 9320 | return; |
| 9321 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9322 | UiccPort uiccPort = phone.getUiccPort(); |
| 9323 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9324 | return; |
| 9325 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9326 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9327 | if (uiccProfile == null) { |
| 9328 | return; |
| 9329 | } |
| 9330 | uiccProfile.refresh(); |
| 9331 | } finally { |
| 9332 | Binder.restoreCallingIdentity(identity); |
| 9333 | } |
| 9334 | } |
| 9335 | |
| 9336 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9337 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9338 | */ |
| 9339 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9340 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9341 | } |
| 9342 | |
| 9343 | /** |
| 9344 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9345 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9346 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9347 | */ |
| 9348 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9349 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9350 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9351 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9352 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9353 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9354 | return isDataRoamingEnabled; |
| 9355 | } |
| 9356 | |
| 9357 | /** |
| 9358 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9359 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9360 | */ |
| 9361 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9362 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9363 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9364 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9365 | return list.get(phoneId); |
| 9366 | } |
| 9367 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9368 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9369 | |
| 9370 | @Override |
| 9371 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9372 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9373 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9374 | |
| 9375 | final long identity = Binder.clearCallingIdentity(); |
| 9376 | try { |
| 9377 | final Phone phone = getPhone(subId); |
| 9378 | if (phone == null) { |
| 9379 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9380 | return; |
| 9381 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9382 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9383 | if (cpt != null) { |
| 9384 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9385 | } |
| 9386 | // TODO(b/211796398): remove the legacy logic below once CPT migration is done. |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9387 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9388 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9389 | if (carrierPrivilegeRules == null) { |
| 9390 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9391 | } else { |
| 9392 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9393 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9394 | } finally { |
| 9395 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9396 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9397 | } |
| 9398 | |
| 9399 | @Override |
| 9400 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9401 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9402 | |
| 9403 | final long identity = Binder.clearCallingIdentity(); |
| 9404 | try { |
| 9405 | final Phone phone = getPhone(subId); |
| 9406 | if (phone == null) { |
| 9407 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9408 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9409 | } |
| 9410 | return phone.getCarrierIdListVersion(); |
| 9411 | } finally { |
| 9412 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9413 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9414 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9415 | |
| 9416 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9417 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9418 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9419 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9420 | mApp, subId, callingPackage, callingFeatureId, |
| 9421 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9422 | return -1; |
| 9423 | } |
| 9424 | |
| 9425 | final long identity = Binder.clearCallingIdentity(); |
| 9426 | try { |
| 9427 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9428 | } finally { |
| 9429 | Binder.restoreCallingIdentity(identity); |
| 9430 | } |
| 9431 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9432 | |
| 9433 | @Override |
| 9434 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9435 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9436 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9437 | mApp, subId, "getCdmaRoamingMode"); |
| 9438 | |
| 9439 | final long identity = Binder.clearCallingIdentity(); |
| 9440 | try { |
| 9441 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9442 | } finally { |
| 9443 | Binder.restoreCallingIdentity(identity); |
| 9444 | } |
| 9445 | } |
| 9446 | |
| 9447 | @Override |
| 9448 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9449 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9450 | mApp, subId, "setCdmaRoamingMode"); |
| 9451 | |
| 9452 | final long identity = Binder.clearCallingIdentity(); |
| 9453 | try { |
| 9454 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9455 | } finally { |
| 9456 | Binder.restoreCallingIdentity(identity); |
| 9457 | } |
| 9458 | } |
| 9459 | |
| 9460 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9461 | public int getCdmaSubscriptionMode(int subId) { |
| 9462 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9463 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9464 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9465 | |
| 9466 | final long identity = Binder.clearCallingIdentity(); |
| 9467 | try { |
| 9468 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9469 | } finally { |
| 9470 | Binder.restoreCallingIdentity(identity); |
| 9471 | } |
| 9472 | } |
| 9473 | |
| 9474 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9475 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9477 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9478 | |
| 9479 | final long identity = Binder.clearCallingIdentity(); |
| 9480 | try { |
| 9481 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9482 | } finally { |
| 9483 | Binder.restoreCallingIdentity(identity); |
| 9484 | } |
| 9485 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9486 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9487 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9488 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9489 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9490 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9491 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9492 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9493 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9494 | } |
| 9495 | final long identity = Binder.clearCallingIdentity(); |
| 9496 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9497 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9498 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9499 | if (phone.getEmergencyNumberTracker() != null |
| 9500 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9501 | emergencyNumberListInternal.put( |
| 9502 | phone.getSubId(), |
| 9503 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9504 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9505 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9506 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9507 | } finally { |
| 9508 | Binder.restoreCallingIdentity(identity); |
| 9509 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9510 | } |
| 9511 | |
| 9512 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9513 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9514 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9515 | if (!exactMatch) { |
| 9516 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9517 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9518 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9519 | } |
| 9520 | final long identity = Binder.clearCallingIdentity(); |
| 9521 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9522 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9523 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9524 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9525 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9526 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9527 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9528 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9529 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9530 | } |
| 9531 | return false; |
| 9532 | } finally { |
| 9533 | Binder.restoreCallingIdentity(identity); |
| 9534 | } |
| 9535 | } |
| 9536 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9537 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9538 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9539 | */ |
| 9540 | @Override |
| 9541 | public void startEmergencyCallbackMode() { |
| 9542 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9543 | "startEmergencyCallbackMode"); |
| 9544 | enforceModifyPermission(); |
| 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | try { |
| 9547 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9548 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9549 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9550 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9551 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9552 | gsmCdmaPhone.obtainMessage( |
| 9553 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9554 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9555 | } |
| 9556 | } |
| 9557 | } finally { |
| 9558 | Binder.restoreCallingIdentity(identity); |
| 9559 | } |
| 9560 | } |
| 9561 | |
| 9562 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9563 | * Update emergency number list for test mode. |
| 9564 | */ |
| 9565 | @Override |
| 9566 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9567 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9568 | "updateEmergencyNumberListTestMode"); |
| 9569 | |
| 9570 | final long identity = Binder.clearCallingIdentity(); |
| 9571 | try { |
| 9572 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9573 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9574 | if (tracker != null) { |
| 9575 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9576 | } |
| 9577 | } |
| 9578 | } finally { |
| 9579 | Binder.restoreCallingIdentity(identity); |
| 9580 | } |
| 9581 | } |
| 9582 | |
| 9583 | /** |
| 9584 | * Get the full emergency number list for test mode. |
| 9585 | */ |
| 9586 | @Override |
| 9587 | public List<String> getEmergencyNumberListTestMode() { |
| 9588 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9589 | "getEmergencyNumberListTestMode"); |
| 9590 | |
| 9591 | final long identity = Binder.clearCallingIdentity(); |
| 9592 | try { |
| 9593 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9594 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9595 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9596 | if (tracker != null) { |
| 9597 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9598 | emergencyNumbers.add(num.getNumber()); |
| 9599 | } |
| 9600 | } |
| 9601 | } |
| 9602 | return new ArrayList<>(emergencyNumbers); |
| 9603 | } finally { |
| 9604 | Binder.restoreCallingIdentity(identity); |
| 9605 | } |
| 9606 | } |
| 9607 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9608 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9609 | public int getEmergencyNumberDbVersion(int subId) { |
| 9610 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9611 | |
| 9612 | final long identity = Binder.clearCallingIdentity(); |
| 9613 | try { |
| 9614 | final Phone phone = getPhone(subId); |
| 9615 | if (phone == null) { |
| 9616 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9617 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9618 | } |
| 9619 | return phone.getEmergencyNumberDbVersion(); |
| 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
| 9625 | @Override |
| 9626 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9627 | enforceModifyPermission(); |
| 9628 | |
| 9629 | final long identity = Binder.clearCallingIdentity(); |
| 9630 | try { |
| 9631 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9632 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9633 | if (tracker != null) { |
| 9634 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9635 | } |
| 9636 | } |
| 9637 | } finally { |
| 9638 | Binder.restoreCallingIdentity(identity); |
| 9639 | } |
| 9640 | } |
| 9641 | |
| 9642 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9643 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9644 | enforceActiveEmergencySessionPermission(); |
| 9645 | |
| 9646 | final long identity = Binder.clearCallingIdentity(); |
| 9647 | try { |
| 9648 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9649 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9650 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9651 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9652 | } |
| 9653 | } |
| 9654 | } finally { |
| 9655 | Binder.restoreCallingIdentity(identity); |
| 9656 | } |
| 9657 | } |
| 9658 | |
| 9659 | @Override |
| 9660 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9661 | enforceActiveEmergencySessionPermission(); |
| 9662 | |
| 9663 | final long identity = Binder.clearCallingIdentity(); |
| 9664 | try { |
| 9665 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9666 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9667 | if (tracker != null) { |
| 9668 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9669 | } |
| 9670 | } |
| 9671 | } finally { |
| 9672 | Binder.restoreCallingIdentity(identity); |
| 9673 | } |
| 9674 | } |
| 9675 | |
| 9676 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9677 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9678 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9679 | Phone phone = getPhone(subId); |
| 9680 | if (phone == null) { |
| 9681 | return null; |
| 9682 | } |
| 9683 | final long identity = Binder.clearCallingIdentity(); |
| 9684 | try { |
| 9685 | UiccProfile profile = UiccController.getInstance() |
| 9686 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9687 | if (profile != null) { |
| 9688 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9689 | } |
| 9690 | } finally { |
| 9691 | Binder.restoreCallingIdentity(identity); |
| 9692 | } |
| 9693 | return null; |
| 9694 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9695 | |
| 9696 | /** |
| 9697 | * Enable or disable a modem stack. |
| 9698 | */ |
| 9699 | @Override |
| 9700 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9701 | enforceModifyPermission(); |
| 9702 | |
| 9703 | final long identity = Binder.clearCallingIdentity(); |
| 9704 | try { |
| 9705 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9706 | if (phone == null) { |
| 9707 | return false; |
| 9708 | } else { |
| 9709 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9710 | } |
| 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
| 9713 | } |
| 9714 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9715 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9716 | /** |
| 9717 | * Whether a modem stack is enabled or not. |
| 9718 | */ |
| 9719 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9720 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9721 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9722 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9723 | if (phone == null) return false; |
| 9724 | |
| 9725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9726 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9727 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9728 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9729 | } |
| 9730 | |
| 9731 | final long identity = Binder.clearCallingIdentity(); |
| 9732 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9733 | try { |
| 9734 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9735 | } catch (NoSuchElementException ex) { |
| 9736 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9737 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(identity); |
| 9740 | } |
| 9741 | } |
| 9742 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9743 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9744 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9745 | enforceModifyPermission(); |
| 9746 | |
| 9747 | final long identity = Binder.clearCallingIdentity(); |
| 9748 | try { |
| 9749 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9750 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9751 | .commit(); |
| 9752 | } finally { |
| 9753 | Binder.restoreCallingIdentity(identity); |
| 9754 | } |
| 9755 | } |
| 9756 | |
| 9757 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9758 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9759 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9761 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9762 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9763 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9764 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9765 | |
| 9766 | final long identity = Binder.clearCallingIdentity(); |
| 9767 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9768 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9769 | } finally { |
| 9770 | Binder.restoreCallingIdentity(identity); |
| 9771 | } |
| 9772 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9773 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9774 | @TelephonyManager.IsMultiSimSupportedResult |
| 9775 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9776 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9777 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9778 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9779 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9780 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9781 | } |
| 9782 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9783 | // supported by the modem, indicate that it is restricted. |
| 9784 | PhoneCapability staticCapability = |
| 9785 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9786 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9787 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9788 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9789 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9790 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9791 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9792 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9793 | } |
| 9794 | // Check if support of multiple SIMs is restricted by carrier |
| 9795 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9796 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9797 | } |
| 9798 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9799 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9800 | } |
| 9801 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9802 | /** |
| 9803 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9804 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9805 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9806 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9807 | * @param numOfSims number of active sims we want to switch to |
| 9808 | */ |
| 9809 | @Override |
| 9810 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9811 | if (numOfSims == 1) { |
| 9812 | enforceModifyPermission(); |
| 9813 | } else { |
| 9814 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9815 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9816 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9817 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9818 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9819 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9820 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9821 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9822 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9823 | return; |
| 9824 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9825 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9826 | } finally { |
| 9827 | Binder.restoreCallingIdentity(identity); |
| 9828 | } |
| 9829 | } |
| 9830 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9831 | @Override |
| 9832 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9833 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9834 | Phone phone = getPhone(subId); |
| 9835 | if (phone == null) { |
| 9836 | return false; |
| 9837 | } |
| 9838 | final long identity = Binder.clearCallingIdentity(); |
| 9839 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9840 | UiccPort uiccPort = phone.getUiccPort(); |
| 9841 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9842 | return false; |
| 9843 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9844 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9845 | if (uiccProfile == null) { |
| 9846 | return false; |
| 9847 | } |
| 9848 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9849 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9850 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9851 | } |
| 9852 | return false; |
| 9853 | } finally { |
| 9854 | Binder.restoreCallingIdentity(identity); |
| 9855 | } |
| 9856 | } |
| 9857 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9858 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9859 | * Get whether making changes to modem configurations will trigger reboot. |
| 9860 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9861 | */ |
| 9862 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9863 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9864 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9865 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9866 | mApp, subId, callingPackage, callingFeatureId, |
| 9867 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9868 | return false; |
| 9869 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9870 | final long identity = Binder.clearCallingIdentity(); |
| 9871 | try { |
| 9872 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9873 | } finally { |
| 9874 | Binder.restoreCallingIdentity(identity); |
| 9875 | } |
| 9876 | } |
| 9877 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9878 | private void updateModemStateMetrics() { |
| 9879 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9880 | // TODO: check the state for each modem if the api is ready. |
| 9881 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9882 | } |
| 9883 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9884 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9885 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9886 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9887 | // Verify that the callingPackage belongs to the calling UID |
| 9888 | mApp.getSystemService(AppOpsManager.class) |
| 9889 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9890 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9891 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9892 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9893 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9894 | if (slotInfos != null) { |
| 9895 | for (int i = 0; i < slotInfos.length; i++) { |
| 9896 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9897 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9898 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9899 | portInfo.getLogicalSlotIndex())); |
| 9900 | } |
| 9901 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9902 | } |
| 9903 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9904 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9905 | } finally { |
| 9906 | Binder.restoreCallingIdentity(identity); |
| 9907 | } |
| 9908 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9909 | |
| 9910 | /** |
| 9911 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9912 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9913 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9914 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9915 | @Override |
| 9916 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9917 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9918 | } |
| 9919 | |
| 9920 | /** |
| 9921 | * Get the HAL Version of a specific service |
| 9922 | */ |
| 9923 | @Override |
| 9924 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9925 | Phone phone = getDefaultPhone(); |
| 9926 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9927 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9928 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9929 | return hv.major * 100 + hv.minor; |
| 9930 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9931 | |
| 9932 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9933 | * Get the current calling package name. |
| 9934 | * @return the current calling package name |
| 9935 | */ |
| 9936 | @Override |
| 9937 | public String getCurrentPackageName() { |
| 9938 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9939 | } |
| 9940 | |
| 9941 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9942 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9943 | * corresponding network requests on a subId. |
| 9944 | * |
| 9945 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9946 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9947 | * 2) APN is un-metered for this subscription, or |
| 9948 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9949 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9950 | * |
| 9951 | * @return whether data is allowed for a apn type. |
| 9952 | * |
| 9953 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9954 | */ |
| 9955 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9956 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9957 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9958 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9959 | |
| 9960 | // Now that all security checks passes, perform the operation as ourselves. |
| 9961 | final long identity = Binder.clearCallingIdentity(); |
| 9962 | try { |
| 9963 | Phone phone = getPhone(subId); |
| 9964 | if (phone == null) return false; |
| 9965 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9966 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9967 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9968 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9969 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9970 | phone.getServiceState().getDataRoaming()); |
| 9971 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9972 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9973 | } finally { |
| 9974 | Binder.restoreCallingIdentity(identity); |
| 9975 | } |
| 9976 | } |
| 9977 | |
| 9978 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9979 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9980 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9981 | |
| 9982 | // Now that all security checks passes, perform the operation as ourselves. |
| 9983 | final long identity = Binder.clearCallingIdentity(); |
| 9984 | try { |
| 9985 | Phone phone = getPhone(subId); |
| 9986 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9987 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9988 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9989 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9990 | } finally { |
| 9991 | Binder.restoreCallingIdentity(identity); |
| 9992 | } |
| 9993 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9994 | |
| 9995 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9996 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9997 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9998 | enforceModifyPermission(); |
| 9999 | long token = Binder.clearCallingIdentity(); |
| 10000 | try { |
| 10001 | Phone phone = getPhone(subscriptionId); |
| 10002 | if (phone == null) { |
| 10003 | try { |
| 10004 | if (resultCallback != null) { |
| 10005 | resultCallback.accept(false); |
| 10006 | } |
| 10007 | } catch (RemoteException e) { |
| 10008 | // ignore |
| 10009 | } |
| 10010 | return; |
| 10011 | } |
| 10012 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10013 | Pair.create(specifiers, (x) -> { |
| 10014 | try { |
| 10015 | if (resultCallback != null) { |
| 10016 | resultCallback.accept(x); |
| 10017 | } |
| 10018 | } catch (RemoteException e) { |
| 10019 | // ignore |
| 10020 | } |
| 10021 | }); |
| 10022 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10023 | } finally { |
| 10024 | Binder.restoreCallingIdentity(token); |
| 10025 | } |
| 10026 | } |
| 10027 | |
| 10028 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10029 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10030 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10031 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10032 | mApp, subId, "getSystemSelectionChannels"); |
| 10033 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10034 | final long identity = Binder.clearCallingIdentity(); |
| 10035 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10036 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10037 | if (result instanceof IllegalStateException) { |
| 10038 | throw (IllegalStateException) result; |
| 10039 | } |
| 10040 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10041 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10042 | return specifiers; |
| 10043 | } finally { |
| 10044 | Binder.restoreCallingIdentity(identity); |
| 10045 | } |
| 10046 | } |
| 10047 | |
| 10048 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10049 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10050 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10051 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10052 | } |
| 10053 | |
| 10054 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10055 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10056 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10057 | if (callingPackage == null) { |
| 10058 | callingPackage = getCurrentPackageName(); |
| 10059 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10060 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10061 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10062 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10063 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10064 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10065 | } |
| 10066 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10067 | Intent intent = new Intent(); |
| 10068 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10069 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10070 | // Bring up choose default SMS subscription dialog right now |
| 10071 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10072 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10073 | mApp.startActivity(intent); |
| 10074 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10075 | |
| 10076 | @Override |
| 10077 | public String getMmsUAProfUrl(int subId) { |
| 10078 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10079 | final long identity = Binder.clearCallingIdentity(); |
| 10080 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10081 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10082 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10083 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10084 | return carrierUAProfUrl; |
| 10085 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10086 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10087 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10088 | } finally { |
| 10089 | Binder.restoreCallingIdentity(identity); |
| 10090 | } |
| 10091 | } |
| 10092 | |
| 10093 | @Override |
| 10094 | public String getMmsUserAgent(int subId) { |
| 10095 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10096 | final long identity = Binder.clearCallingIdentity(); |
| 10097 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10098 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10099 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10100 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10101 | return carrierUserAgent; |
| 10102 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10103 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10104 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10105 | } finally { |
| 10106 | Binder.restoreCallingIdentity(identity); |
| 10107 | } |
| 10108 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10109 | |
| 10110 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10111 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10112 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10113 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10114 | final long identity = Binder.clearCallingIdentity(); |
| 10115 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10116 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10117 | if (phone == null) return false; |
| 10118 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10119 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10120 | } finally { |
| 10121 | Binder.restoreCallingIdentity(identity); |
| 10122 | } |
| 10123 | } |
| 10124 | |
| 10125 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10126 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10127 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10128 | enforceModifyPermission(); |
| 10129 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10130 | final long identity = Binder.clearCallingIdentity(); |
| 10131 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10132 | Phone phone = getPhone(subscriptionId); |
| 10133 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10134 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10135 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10136 | } finally { |
| 10137 | Binder.restoreCallingIdentity(identity); |
| 10138 | } |
| 10139 | } |
| 10140 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10141 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10142 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10143 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10144 | * otherwise. |
| 10145 | */ |
| 10146 | @Override |
| 10147 | public void setCepEnabled(boolean isCepEnabled) { |
| 10148 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10149 | |
| 10150 | final long identity = Binder.clearCallingIdentity(); |
| 10151 | try { |
| 10152 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10153 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10154 | Phone defaultPhone = phone.getImsPhone(); |
| 10155 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10156 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10157 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10158 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10159 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10160 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10161 | + imsPhone.getMsisdn()); |
| 10162 | } |
| 10163 | } |
| 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10168 | |
| 10169 | /** |
| 10170 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10171 | * |
| 10172 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10173 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10174 | * before being read. |
| 10175 | */ |
| 10176 | @Override |
| 10177 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10178 | isCompressed) { |
| 10179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10180 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10181 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10182 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10183 | } |
| 10184 | if (!isImsAvailableOnDevice()) { |
| 10185 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10186 | "IMS not available on device."); |
| 10187 | } |
| 10188 | |
| 10189 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10190 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10191 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10192 | } finally { |
| 10193 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10194 | } |
| 10195 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10196 | |
| 10197 | @Override |
| 10198 | public boolean isIccLockEnabled(int subId) { |
| 10199 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10200 | |
| 10201 | // Now that all security checks passes, perform the operation as ourselves. |
| 10202 | final long identity = Binder.clearCallingIdentity(); |
| 10203 | try { |
| 10204 | Phone phone = getPhone(subId); |
| 10205 | if (phone != null && phone.getIccCard() != null) { |
| 10206 | return phone.getIccCard().getIccLockEnabled(); |
| 10207 | } else { |
| 10208 | return false; |
| 10209 | } |
| 10210 | } finally { |
| 10211 | Binder.restoreCallingIdentity(identity); |
| 10212 | } |
| 10213 | } |
| 10214 | |
| 10215 | /** |
| 10216 | * Set the ICC pin lock enabled or disabled. |
| 10217 | * |
| 10218 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10219 | * three cases: |
| 10220 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10221 | * successfully. |
| 10222 | * - Positive number and zero for remaining password attempts. |
| 10223 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10224 | * |
| 10225 | */ |
| 10226 | @Override |
| 10227 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10228 | enforceModifyPermission(); |
| 10229 | |
| 10230 | Phone phone = getPhone(subId); |
| 10231 | if (phone == null) { |
| 10232 | return 0; |
| 10233 | } |
| 10234 | // Now that all security checks passes, perform the operation as ourselves. |
| 10235 | final long identity = Binder.clearCallingIdentity(); |
| 10236 | try { |
| 10237 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10238 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10239 | return attemptsRemaining; |
| 10240 | |
| 10241 | } catch (Exception e) { |
| 10242 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10243 | } finally { |
| 10244 | Binder.restoreCallingIdentity(identity); |
| 10245 | } |
| 10246 | return 0; |
| 10247 | } |
| 10248 | |
| 10249 | /** |
| 10250 | * Change the ICC password used in ICC pin lock. |
| 10251 | * |
| 10252 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10253 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10254 | * - Positive number and zero for remaining password attempts. |
| 10255 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10256 | * |
| 10257 | */ |
| 10258 | @Override |
| 10259 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10260 | enforceModifyPermission(); |
| 10261 | |
| 10262 | Phone phone = getPhone(subId); |
| 10263 | if (phone == null) { |
| 10264 | return 0; |
| 10265 | } |
| 10266 | // Now that all security checks passes, perform the operation as ourselves. |
| 10267 | final long identity = Binder.clearCallingIdentity(); |
| 10268 | try { |
| 10269 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10270 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10271 | return attemptsRemaining; |
| 10272 | |
| 10273 | } catch (Exception e) { |
| 10274 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10275 | } finally { |
| 10276 | Binder.restoreCallingIdentity(identity); |
| 10277 | } |
| 10278 | return 0; |
| 10279 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10280 | |
| 10281 | /** |
| 10282 | * Request for receiving user activity notification |
| 10283 | */ |
| 10284 | @Override |
| 10285 | public void requestUserActivityNotification() { |
| 10286 | if (!mNotifyUserActivity.get() |
| 10287 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10288 | mNotifyUserActivity.set(true); |
| 10289 | } |
| 10290 | } |
| 10291 | |
| 10292 | /** |
| 10293 | * Called when userActivity is signalled in the power manager. |
| 10294 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10295 | */ |
| 10296 | @Override |
| 10297 | public void userActivity() { |
| 10298 | // *************************************** |
| 10299 | // * Inherited from PhoneWindowManager * |
| 10300 | // *************************************** |
| 10301 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10302 | // WITH ITS LOCKS HELD. |
| 10303 | // |
| 10304 | // This code must be VERY careful about the locks |
| 10305 | // it acquires. |
| 10306 | // In fact, the current code acquires way too many, |
| 10307 | // and probably has lurking deadlocks. |
| 10308 | |
| 10309 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10310 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10311 | } |
| 10312 | |
| 10313 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10314 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10315 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10316 | } |
| 10317 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10318 | |
| 10319 | @Override |
| 10320 | public boolean canConnectTo5GInDsdsMode() { |
| 10321 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10322 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10323 | |
| 10324 | @Override |
| 10325 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10326 | String callingFeatureId) { |
| 10327 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10328 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10329 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10330 | } |
| 10331 | |
| 10332 | Phone phone = getPhone(subId); |
| 10333 | if (phone == null) { |
| 10334 | throw new RuntimeException("phone is not available"); |
| 10335 | } |
| 10336 | // Now that all security checks passes, perform the operation as ourselves. |
| 10337 | final long identity = Binder.clearCallingIdentity(); |
| 10338 | try { |
| 10339 | return phone.getEquivalentHomePlmns(); |
| 10340 | } finally { |
| 10341 | Binder.restoreCallingIdentity(identity); |
| 10342 | } |
| 10343 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10344 | |
| 10345 | @Override |
| 10346 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10347 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10348 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10349 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10350 | if (radioInterfaceCapabilities == null) { |
| 10351 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10352 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10353 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10354 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10355 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10356 | @Override |
| 10357 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10358 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10359 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10360 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10361 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10362 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10363 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10364 | if (DBG) { |
| 10365 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10366 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10367 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10368 | } |
| 10369 | |
| 10370 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10371 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10372 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10373 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10374 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10375 | if (callback != null) { |
| 10376 | try { |
| 10377 | callback.onAuthenticationFailure( |
| 10378 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10379 | } catch (RemoteException exception) { |
| 10380 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10381 | } |
| 10382 | return; |
| 10383 | } |
| 10384 | } |
| 10385 | |
| 10386 | final long token = Binder.clearCallingIdentity(); |
| 10387 | try { |
| 10388 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10389 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10390 | forceBootStrapping, callback)); |
| 10391 | } finally { |
| 10392 | Binder.restoreCallingIdentity(token); |
| 10393 | } |
| 10394 | } |
| 10395 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10396 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10397 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10398 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10399 | * requested radio power state will actually be set. See {@link |
| 10400 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10401 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10402 | * @param enable {@code true} if trying to turn radio on. |
| 10403 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10404 | * false}. |
| 10405 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10406 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10407 | boolean isPhoneAvailable = false; |
| 10408 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10409 | Phone phone = PhoneFactory.getPhone(i); |
| 10410 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10411 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10412 | isPhoneAvailable = true; |
| 10413 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10414 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10415 | |
| 10416 | // return true if successfully informed the phone object about the thermal radio power |
| 10417 | // request. |
| 10418 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10419 | } |
| 10420 | |
| 10421 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10422 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10423 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10424 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10425 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10426 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10427 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10428 | } |
| 10429 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10430 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10431 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10432 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10433 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10434 | } |
| 10435 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10436 | setDataEnabledForReason( |
| 10437 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10438 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10439 | if (isDataThrottlingSupported) { |
| 10440 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10441 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10442 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10443 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10444 | } else if (thermalMitigationResult |
| 10445 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10446 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10447 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10448 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10449 | } |
| 10450 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10451 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10452 | |
| 10453 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10454 | } |
| 10455 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10456 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10457 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10458 | for (String pckg : context.getResources() |
| 10459 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10460 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10461 | } |
| 10462 | } |
| 10463 | |
| 10464 | return sThermalMitigationAllowlistedPackages; |
| 10465 | } |
| 10466 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10467 | private boolean isAnyPhoneInEmergencyState() { |
| 10468 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10469 | if (tm.isInEmergencyCall()) { |
| 10470 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10471 | return true; |
| 10472 | } |
| 10473 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10474 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10475 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10476 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10477 | + phone.isInEcm()); |
| 10478 | return true; |
| 10479 | } |
| 10480 | } |
| 10481 | |
| 10482 | return false; |
| 10483 | } |
| 10484 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10485 | /** |
| 10486 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10487 | * @param packageName name of package to be allowlisted |
| 10488 | * @param context |
| 10489 | */ |
| 10490 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10491 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10492 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10493 | } |
| 10494 | |
| 10495 | /** |
| 10496 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10497 | * @param packageName name of package to remove from allowlist |
| 10498 | * @param context |
| 10499 | */ |
| 10500 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10501 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10502 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10503 | } |
| 10504 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10505 | /** |
| 10506 | * Thermal mitigation request to control functionalities at modem. |
| 10507 | * |
| 10508 | * @param subId the id of the subscription. |
| 10509 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10510 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10511 | * |
| 10512 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10513 | */ |
| 10514 | @Override |
| 10515 | @ThermalMitigationResult |
| 10516 | public int sendThermalMitigationRequest( |
| 10517 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10518 | ThermalMitigationRequest thermalMitigationRequest, |
| 10519 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10520 | enforceModifyPermission(); |
| 10521 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10522 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10523 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10524 | .contains(callingPackage)) { |
| 10525 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10526 | + "calling package: " + callingPackage); |
| 10527 | } |
| 10528 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10529 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10530 | final long identity = Binder.clearCallingIdentity(); |
| 10531 | |
| 10532 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10533 | try { |
| 10534 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10535 | switch (thermalMitigationAction) { |
| 10536 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10537 | thermalMitigationResult = |
| 10538 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10539 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10540 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10541 | break; |
| 10542 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10543 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10544 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10545 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10546 | } |
| 10547 | |
| 10548 | // Ensure that radio is on. If not able to power on due to phone being |
| 10549 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10550 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10551 | thermalMitigationResult = |
| 10552 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10553 | break; |
| 10554 | } |
| 10555 | |
| 10556 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10557 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10558 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10559 | break; |
| 10560 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10561 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10562 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10563 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10564 | } |
| 10565 | |
| 10566 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10567 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10568 | Phone phone = getPhone(subId); |
| 10569 | if (phone == null) { |
| 10570 | thermalMitigationResult = |
| 10571 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10572 | break; |
| 10573 | } |
| 10574 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10575 | TelephonyConnectionService service = |
| 10576 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10577 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10578 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10579 | thermalMitigationResult = |
| 10580 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10581 | break; |
| 10582 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10583 | thermalMitigationResult = |
| 10584 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10585 | break; |
| 10586 | } |
| 10587 | } else { |
| 10588 | thermalMitigationResult = |
| 10589 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10590 | break; |
| 10591 | } |
| 10592 | |
| 10593 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10594 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10595 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10596 | thermalMitigationResult = |
| 10597 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10598 | break; |
| 10599 | } |
| 10600 | thermalMitigationResult = |
| 10601 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10602 | break; |
| 10603 | default: |
| 10604 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10605 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10606 | } |
| 10607 | } catch (IllegalArgumentException e) { |
| 10608 | throw e; |
| 10609 | } catch (Exception e) { |
| 10610 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10611 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10612 | } finally { |
| 10613 | Binder.restoreCallingIdentity(identity); |
| 10614 | } |
| 10615 | |
| 10616 | if (DBG) { |
| 10617 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10618 | + thermalMitigationResult); |
| 10619 | } |
| 10620 | |
| 10621 | return thermalMitigationResult; |
| 10622 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10623 | |
| 10624 | /** |
| 10625 | * Set the GbaService Package Name that Telephony will bind to. |
| 10626 | * |
| 10627 | * @param subId The sim that the GbaService is associated with. |
| 10628 | * @param packageName The name of the package to be replaced with. |
| 10629 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10630 | */ |
| 10631 | @Override |
| 10632 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10633 | enforceModifyPermission(); |
| 10634 | |
| 10635 | final long identity = Binder.clearCallingIdentity(); |
| 10636 | try { |
| 10637 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10638 | } finally { |
| 10639 | Binder.restoreCallingIdentity(identity); |
| 10640 | } |
| 10641 | } |
| 10642 | |
| 10643 | /** |
| 10644 | * Return the package name of the currently bound GbaService. |
| 10645 | * |
| 10646 | * @param subId The sim that the GbaService is associated with. |
| 10647 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10648 | */ |
| 10649 | @Override |
| 10650 | public String getBoundGbaService(int subId) { |
| 10651 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10652 | |
| 10653 | final long identity = Binder.clearCallingIdentity(); |
| 10654 | try { |
| 10655 | return getGbaManager(subId).getServicePackage(); |
| 10656 | } finally { |
| 10657 | Binder.restoreCallingIdentity(identity); |
| 10658 | } |
| 10659 | } |
| 10660 | |
| 10661 | /** |
| 10662 | * Set the release time for telephony to unbind GbaService. |
| 10663 | * |
| 10664 | * @param subId The sim that the GbaService is associated with. |
| 10665 | * @param interval The release time to unbind GbaService by millisecond. |
| 10666 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10667 | */ |
| 10668 | @Override |
| 10669 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10670 | enforceModifyPermission(); |
| 10671 | |
| 10672 | final long identity = Binder.clearCallingIdentity(); |
| 10673 | try { |
| 10674 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | } |
| 10679 | |
| 10680 | /** |
| 10681 | * Return the release time for telephony to unbind GbaService. |
| 10682 | * |
| 10683 | * @param subId The sim that the GbaService is associated with. |
| 10684 | * @return The release time to unbind GbaService by millisecond. |
| 10685 | */ |
| 10686 | @Override |
| 10687 | public int getGbaReleaseTime(int subId) { |
| 10688 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10689 | |
| 10690 | final long identity = Binder.clearCallingIdentity(); |
| 10691 | try { |
| 10692 | return getGbaManager(subId).getReleaseTime(); |
| 10693 | } finally { |
| 10694 | Binder.restoreCallingIdentity(identity); |
| 10695 | } |
| 10696 | } |
| 10697 | |
| 10698 | private GbaManager getGbaManager(int subId) { |
| 10699 | GbaManager instance = GbaManager.getInstance(subId); |
| 10700 | if (instance == null) { |
| 10701 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10702 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10703 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10704 | } |
| 10705 | return instance; |
| 10706 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10707 | |
| 10708 | /** |
| 10709 | * indicate whether the device and the carrier can support |
| 10710 | * RCS VoLTE single registration. |
| 10711 | */ |
| 10712 | @Override |
| 10713 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10714 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10715 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10716 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10717 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10718 | |
| 10719 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10720 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10721 | } |
| 10722 | |
| 10723 | final long identity = Binder.clearCallingIdentity(); |
| 10724 | try { |
| 10725 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10726 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10727 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10728 | if (isCapable != null) { |
| 10729 | return isCapable; |
| 10730 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10731 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10732 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10733 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10734 | } finally { |
| 10735 | Binder.restoreCallingIdentity(identity); |
| 10736 | } |
| 10737 | } |
| 10738 | |
| 10739 | /** |
| 10740 | * Register RCS provisioning callback. |
| 10741 | */ |
| 10742 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10743 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10744 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10745 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10746 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10747 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10748 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10749 | |
| 10750 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10751 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10752 | } |
| 10753 | if (!isImsAvailableOnDevice()) { |
| 10754 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10755 | "IMS not available on device."); |
| 10756 | } |
| 10757 | |
| 10758 | final long identity = Binder.clearCallingIdentity(); |
| 10759 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10760 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10761 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10762 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10763 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10764 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10765 | } finally { |
| 10766 | Binder.restoreCallingIdentity(identity); |
| 10767 | } |
| 10768 | } |
| 10769 | |
| 10770 | /** |
| 10771 | * Unregister RCS provisioning callback. |
| 10772 | */ |
| 10773 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10774 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10775 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10776 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10777 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10778 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10779 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10780 | |
| 10781 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10782 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10783 | } |
| 10784 | if (!isImsAvailableOnDevice()) { |
| 10785 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10786 | "IMS not available on device."); |
| 10787 | } |
| 10788 | |
| 10789 | final long identity = Binder.clearCallingIdentity(); |
| 10790 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10791 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10792 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10793 | } finally { |
| 10794 | Binder.restoreCallingIdentity(identity); |
| 10795 | } |
| 10796 | } |
| 10797 | |
| 10798 | /** |
| 10799 | * trigger RCS reconfiguration. |
| 10800 | */ |
| 10801 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10802 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10803 | "triggerRcsReconfiguration", |
| 10804 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10805 | |
| 10806 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10807 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10808 | } |
| 10809 | if (!isImsAvailableOnDevice()) { |
| 10810 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10811 | "IMS not available on device."); |
| 10812 | } |
| 10813 | |
| 10814 | final long identity = Binder.clearCallingIdentity(); |
| 10815 | try { |
| 10816 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10817 | } finally { |
| 10818 | Binder.restoreCallingIdentity(identity); |
| 10819 | } |
| 10820 | } |
| 10821 | |
| 10822 | /** |
| 10823 | * Provide the client configuration parameters of the RCS application. |
| 10824 | */ |
| 10825 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10826 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10827 | "setRcsClientConfiguration", |
| 10828 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10829 | |
| 10830 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10831 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10832 | } |
| 10833 | if (!isImsAvailableOnDevice()) { |
| 10834 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10835 | "IMS not available on device."); |
| 10836 | } |
| 10837 | |
| 10838 | final long identity = Binder.clearCallingIdentity(); |
| 10839 | |
| 10840 | try { |
| 10841 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10842 | if (configBinder == null) { |
| 10843 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10844 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10845 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10846 | } else { |
| 10847 | configBinder.setRcsClientConfiguration(rcc); |
| 10848 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10849 | |
| 10850 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10851 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10852 | } catch (RemoteException e) { |
| 10853 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10854 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10855 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10856 | } finally { |
| 10857 | Binder.restoreCallingIdentity(identity); |
| 10858 | } |
| 10859 | } |
| 10860 | |
| 10861 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10862 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10863 | */ |
| 10864 | @Override |
| 10865 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10866 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10867 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10868 | |
| 10869 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10870 | } |
| 10871 | |
| 10872 | /** |
| 10873 | * Gets the test mode for RCS VoLTE single registration. |
| 10874 | */ |
| 10875 | @Override |
| 10876 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10877 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10878 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10879 | |
| 10880 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10881 | } |
| 10882 | |
| 10883 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10884 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10885 | */ |
| 10886 | @Override |
| 10887 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10888 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10889 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10890 | enforceModifyPermission(); |
| 10891 | |
| 10892 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10893 | : Boolean.parseBoolean(enabledStr); |
| 10894 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10895 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10896 | } |
| 10897 | |
| 10898 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10899 | * Sends a device to device communication message. Only usable via shell. |
| 10900 | * @param message message to send. |
| 10901 | * @param value message value. |
| 10902 | */ |
| 10903 | @Override |
| 10904 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10905 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10906 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10907 | enforceModifyPermission(); |
| 10908 | |
| 10909 | final long identity = Binder.clearCallingIdentity(); |
| 10910 | try { |
| 10911 | TelephonyConnectionService service = |
| 10912 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10913 | if (service == null) { |
| 10914 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10915 | return; |
| 10916 | } |
| 10917 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10918 | } finally { |
| 10919 | Binder.restoreCallingIdentity(identity); |
| 10920 | } |
| 10921 | } |
| 10922 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10923 | /** |
| 10924 | * Sets the specified device to device transport active. |
| 10925 | * @param transport The transport to set active. |
| 10926 | */ |
| 10927 | @Override |
| 10928 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10929 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10930 | "setActiveDeviceToDeviceTransport"); |
| 10931 | enforceModifyPermission(); |
| 10932 | |
| 10933 | final long identity = Binder.clearCallingIdentity(); |
| 10934 | try { |
| 10935 | TelephonyConnectionService service = |
| 10936 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10937 | if (service == null) { |
| 10938 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10939 | return; |
| 10940 | } |
| 10941 | service.setActiveDeviceToDeviceTransport(transport); |
| 10942 | } finally { |
| 10943 | Binder.restoreCallingIdentity(identity); |
| 10944 | } |
| 10945 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10946 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10947 | @Override |
| 10948 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10949 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10950 | "setDeviceToDeviceForceEnabled"); |
| 10951 | |
| 10952 | final long identity = Binder.clearCallingIdentity(); |
| 10953 | try { |
| 10954 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10955 | p -> { |
| 10956 | Phone thePhone = p.getImsPhone(); |
| 10957 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10958 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10959 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10960 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10961 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10962 | (ImsPhoneCallTracker) tracker; |
| 10963 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10964 | } |
| 10965 | } |
| 10966 | } |
| 10967 | ); |
| 10968 | } finally { |
| 10969 | Binder.restoreCallingIdentity(identity); |
| 10970 | } |
| 10971 | } |
| 10972 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10973 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10974 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10975 | */ |
| 10976 | @Override |
| 10977 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10978 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10979 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10980 | } |
| 10981 | |
| 10982 | /** |
| 10983 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10984 | */ |
| 10985 | @Override |
| 10986 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10987 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10988 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10989 | enforceModifyPermission(); |
| 10990 | |
| 10991 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10992 | : Boolean.parseBoolean(enabledStr); |
| 10993 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10994 | subId, enabled); |
| 10995 | } |
| 10996 | |
| 10997 | /** |
| 10998 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10999 | */ |
| 11000 | @Override |
| 11001 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11002 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11003 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11004 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11005 | |
| 11006 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11007 | * Overrides the ims feature validation result |
| 11008 | */ |
| 11009 | @Override |
| 11010 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11011 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11012 | "setImsFeatureValidationOverride"); |
| 11013 | |
| 11014 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11015 | : Boolean.parseBoolean(enabledStr); |
| 11016 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11017 | subId, enabled); |
| 11018 | } |
| 11019 | |
| 11020 | /** |
| 11021 | * Gets the ims feature validation override value |
| 11022 | */ |
| 11023 | @Override |
| 11024 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11025 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11026 | "getImsFeatureValidationOverride"); |
| 11027 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11028 | } |
| 11029 | |
| 11030 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11031 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11032 | * their mobile plan. |
| 11033 | */ |
| 11034 | @Override |
| 11035 | public String getMobileProvisioningUrl() { |
| 11036 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11037 | final long identity = Binder.clearCallingIdentity(); |
| 11038 | try { |
| 11039 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11040 | } finally { |
| 11041 | Binder.restoreCallingIdentity(identity); |
| 11042 | } |
| 11043 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11044 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11045 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11046 | * Get the EAB contact from the EAB database. |
| 11047 | */ |
| 11048 | @Override |
| 11049 | public String getContactFromEab(String contact) { |
| 11050 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11051 | enforceModifyPermission(); |
| 11052 | final long identity = Binder.clearCallingIdentity(); |
| 11053 | try { |
| 11054 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11055 | } finally { |
| 11056 | Binder.restoreCallingIdentity(identity); |
| 11057 | } |
| 11058 | } |
| 11059 | |
| 11060 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11061 | * Get the EAB capability from the EAB database. |
| 11062 | */ |
| 11063 | @Override |
| 11064 | public String getCapabilityFromEab(String contact) { |
| 11065 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11066 | enforceModifyPermission(); |
| 11067 | final long identity = Binder.clearCallingIdentity(); |
| 11068 | try { |
| 11069 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11070 | } finally { |
| 11071 | Binder.restoreCallingIdentity(identity); |
| 11072 | } |
| 11073 | } |
| 11074 | |
| 11075 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11076 | * Remove the EAB contacts from the EAB database. |
| 11077 | */ |
| 11078 | @Override |
| 11079 | public int removeContactFromEab(int subId, String contacts) { |
| 11080 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11081 | enforceModifyPermission(); |
| 11082 | final long identity = Binder.clearCallingIdentity(); |
| 11083 | try { |
| 11084 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11085 | } finally { |
| 11086 | Binder.restoreCallingIdentity(identity); |
| 11087 | } |
| 11088 | } |
| 11089 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11090 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11091 | public boolean getDeviceUceEnabled() { |
| 11092 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11093 | final long identity = Binder.clearCallingIdentity(); |
| 11094 | try { |
| 11095 | return mApp.getDeviceUceEnabled(); |
| 11096 | } finally { |
| 11097 | Binder.restoreCallingIdentity(identity); |
| 11098 | } |
| 11099 | } |
| 11100 | |
| 11101 | @Override |
| 11102 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11103 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11104 | final long identity = Binder.clearCallingIdentity(); |
| 11105 | try { |
| 11106 | mApp.setDeviceUceEnabled(isEnabled); |
| 11107 | } finally { |
| 11108 | Binder.restoreCallingIdentity(identity); |
| 11109 | } |
| 11110 | } |
| 11111 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11112 | /** |
| 11113 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11114 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11115 | */ |
| 11116 | // Used for SHELL command only right now. |
| 11117 | @Override |
| 11118 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11119 | List<String> featureTags) { |
| 11120 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11121 | "addUceRegistrationOverrideShell"); |
| 11122 | final long identity = Binder.clearCallingIdentity(); |
| 11123 | try { |
| 11124 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11125 | new ArraySet<>(featureTags)); |
| 11126 | } catch (ImsException e) { |
| 11127 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11128 | } finally { |
| 11129 | Binder.restoreCallingIdentity(identity); |
| 11130 | } |
| 11131 | } |
| 11132 | |
| 11133 | /** |
| 11134 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11135 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11136 | */ |
| 11137 | // Used for SHELL command only right now. |
| 11138 | @Override |
| 11139 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11140 | List<String> featureTags) { |
| 11141 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11142 | "removeUceRegistrationOverrideShell"); |
| 11143 | final long identity = Binder.clearCallingIdentity(); |
| 11144 | try { |
| 11145 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11146 | new ArraySet<>(featureTags)); |
| 11147 | } catch (ImsException e) { |
| 11148 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11149 | } finally { |
| 11150 | Binder.restoreCallingIdentity(identity); |
| 11151 | } |
| 11152 | } |
| 11153 | |
| 11154 | /** |
| 11155 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11156 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11157 | */ |
| 11158 | // Used for SHELL command only right now. |
| 11159 | @Override |
| 11160 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11161 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11162 | "clearUceRegistrationOverrideShell"); |
| 11163 | final long identity = Binder.clearCallingIdentity(); |
| 11164 | try { |
| 11165 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11166 | } catch (ImsException e) { |
| 11167 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11168 | } finally { |
| 11169 | Binder.restoreCallingIdentity(identity); |
| 11170 | } |
| 11171 | } |
| 11172 | |
| 11173 | /** |
| 11174 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11175 | */ |
| 11176 | // Used for SHELL command only right now. |
| 11177 | @Override |
| 11178 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11179 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11180 | "getLatestRcsContactUceCapabilityShell"); |
| 11181 | final long identity = Binder.clearCallingIdentity(); |
| 11182 | try { |
| 11183 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11184 | } catch (ImsException e) { |
| 11185 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11186 | } finally { |
| 11187 | Binder.restoreCallingIdentity(identity); |
| 11188 | } |
| 11189 | } |
| 11190 | |
| 11191 | /** |
| 11192 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11193 | * device does not have an active PUBLISH. |
| 11194 | */ |
| 11195 | // Used for SHELL command only right now. |
| 11196 | @Override |
| 11197 | public String getLastUcePidfXmlShell(int subId) { |
| 11198 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11199 | final long identity = Binder.clearCallingIdentity(); |
| 11200 | try { |
| 11201 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11202 | } catch (ImsException e) { |
| 11203 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11204 | } finally { |
| 11205 | Binder.restoreCallingIdentity(identity); |
| 11206 | } |
| 11207 | } |
| 11208 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11209 | /** |
| 11210 | * Remove UCE requests cannot be sent to the network status. |
| 11211 | */ |
| 11212 | // Used for SHELL command only right now. |
| 11213 | @Override |
| 11214 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11215 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11216 | final long identity = Binder.clearCallingIdentity(); |
| 11217 | try { |
| 11218 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11219 | } catch (ImsException e) { |
| 11220 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11221 | } finally { |
| 11222 | Binder.restoreCallingIdentity(identity); |
| 11223 | } |
| 11224 | } |
| 11225 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11226 | /** |
| 11227 | * Remove UCE requests cannot be sent to the network status. |
| 11228 | */ |
| 11229 | // Used for SHELL command only. |
| 11230 | @Override |
| 11231 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11232 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11233 | final long identity = Binder.clearCallingIdentity(); |
| 11234 | try { |
| 11235 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11236 | } catch (ImsException e) { |
| 11237 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11238 | } finally { |
| 11239 | Binder.restoreCallingIdentity(identity); |
| 11240 | } |
| 11241 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11242 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11243 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11244 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11245 | String callingPackage) { |
| 11246 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11247 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11248 | |
| 11249 | final int callingUid = Binder.getCallingUid(); |
| 11250 | // Verify that tha callingPackage belongs to the calling UID |
| 11251 | mApp.getSystemService(AppOpsManager.class) |
| 11252 | .checkPackage(callingUid, callingPackage); |
| 11253 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11254 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11255 | |
| 11256 | final long identity = Binder.clearCallingIdentity(); |
| 11257 | try { |
| 11258 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11259 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11260 | |
| 11261 | if (result instanceof IllegalStateException) { |
| 11262 | throw (IllegalStateException) result; |
| 11263 | } |
| 11264 | } finally { |
| 11265 | Binder.restoreCallingIdentity(identity); |
| 11266 | } |
| 11267 | } |
| 11268 | |
| 11269 | @Override |
| 11270 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11271 | String callingPackage) { |
| 11272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11273 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11274 | |
| 11275 | final int callingUid = Binder.getCallingUid(); |
| 11276 | // Verify that tha callingPackage belongs to the calling UID |
| 11277 | mApp.getSystemService(AppOpsManager.class) |
| 11278 | .checkPackage(callingUid, callingPackage); |
| 11279 | |
| 11280 | final long identity = Binder.clearCallingIdentity(); |
| 11281 | try { |
| 11282 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11283 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11284 | |
| 11285 | if (result instanceof IllegalStateException) { |
| 11286 | throw (IllegalStateException) result; |
| 11287 | } |
| 11288 | } finally { |
| 11289 | Binder.restoreCallingIdentity(identity); |
| 11290 | } |
| 11291 | } |
| 11292 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11293 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11294 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11295 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11296 | // phone/system process do not have further restriction on request |
| 11297 | return; |
| 11298 | } |
| 11299 | |
| 11300 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11301 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11302 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11303 | context.enforceCallingOrSelfPermission( |
| 11304 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11305 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11306 | } |
| 11307 | |
| 11308 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11309 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11310 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11311 | || info.isEnabled()) { |
| 11312 | throw new IllegalArgumentException( |
| 11313 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11314 | } |
| 11315 | |
| 11316 | // Thresholds length for each RAN need in range. This has been validated in |
| 11317 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11318 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11319 | final int[] thresholds = info.getThresholds(); |
| 11320 | Objects.requireNonNull(thresholds); |
| 11321 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11322 | || thresholds.length |
| 11323 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11324 | throw new IllegalArgumentException( |
| 11325 | "thresholds length is out of range: " + thresholds.length); |
| 11326 | } |
| 11327 | } |
| 11328 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11329 | |
| 11330 | /** |
| 11331 | * Gets the current phone capability. |
| 11332 | * |
| 11333 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11334 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11335 | * It's used to evaluate possible phone config change, for example from single |
| 11336 | * SIM device to multi-SIM device. |
| 11337 | */ |
| 11338 | @Override |
| 11339 | public PhoneCapability getPhoneCapability() { |
| 11340 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11341 | final long identity = Binder.clearCallingIdentity(); |
| 11342 | try { |
| 11343 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11344 | } finally { |
| 11345 | Binder.restoreCallingIdentity(identity); |
| 11346 | } |
| 11347 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11348 | |
| 11349 | /** |
| 11350 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11351 | * required to be done shortly after the API is invoked. |
| 11352 | */ |
| 11353 | @Override |
| 11354 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11355 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11356 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11357 | enforceRebootPermission(); |
| 11358 | |
| 11359 | final long identity = Binder.clearCallingIdentity(); |
| 11360 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11361 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11362 | } finally { |
| 11363 | Binder.restoreCallingIdentity(identity); |
| 11364 | } |
| 11365 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11366 | |
| 11367 | /** |
| 11368 | * Request to get the current slicing configuration including URSP rules and |
| 11369 | * NSSAIs (configured, allowed and rejected). |
| 11370 | * |
| 11371 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11372 | */ |
| 11373 | @Override |
| 11374 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11375 | TelephonyPermissions |
| 11376 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11377 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11378 | |
| 11379 | final long identity = Binder.clearCallingIdentity(); |
| 11380 | try { |
| 11381 | Phone phone = getDefaultPhone(); |
| 11382 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11383 | } finally { |
| 11384 | Binder.restoreCallingIdentity(identity); |
| 11385 | } |
| 11386 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11387 | |
| 11388 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11389 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11390 | * |
| 11391 | * @param capability The premium capability to check. |
| 11392 | * @param subId The subId to check the premium capability for. |
| 11393 | * |
| 11394 | * @return Whether the given premium capability is available to purchase. |
| 11395 | */ |
| 11396 | @Override |
| 11397 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11398 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11399 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11400 | log("Premium capability " |
| 11401 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11402 | + " is not available for purchase due to missing permissions."); |
| 11403 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11404 | + "permission READ_BASIC_PHONE_STATE."); |
| 11405 | } |
| 11406 | |
| 11407 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11408 | if (phone == null) { |
| 11409 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11410 | return false; |
| 11411 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11412 | final long identity = Binder.clearCallingIdentity(); |
| 11413 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11414 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11415 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11416 | } finally { |
| 11417 | Binder.restoreCallingIdentity(identity); |
| 11418 | } |
| 11419 | } |
| 11420 | |
| 11421 | /** |
| 11422 | * Purchase the given premium capability from the carrier. |
| 11423 | * |
| 11424 | * @param capability The premium capability to purchase. |
| 11425 | * @param callback The result of the purchase request. |
| 11426 | * @param subId The subId to purchase the premium capability for. |
| 11427 | */ |
| 11428 | @Override |
| 11429 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11430 | log("purchasePremiumCapability: capability=" |
| 11431 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11432 | + getCurrentPackageName()); |
| 11433 | |
| 11434 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11435 | mApp, "purchasePremiumCapability")) { |
| 11436 | log("purchasePremiumCapability " |
| 11437 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11438 | + " failed due to missing permissions."); |
| 11439 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11440 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11441 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11442 | mApp, "purchasePremiumCapability")) { |
| 11443 | log("purchasePremiumCapability " |
| 11444 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11445 | + " failed due to missing permissions."); |
| 11446 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11447 | } |
| 11448 | |
| 11449 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11450 | if (phone == null) { |
| 11451 | try { |
| 11452 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11453 | callback.accept(result); |
| 11454 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11455 | } catch (RemoteException e) { |
| 11456 | String logStr = "Purchase premium capability " |
| 11457 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11458 | + " failed due to RemoteException handling null phone: " + e; |
| 11459 | if (DBG) log(logStr); |
| 11460 | AnomalyReporter.reportAnomaly( |
| 11461 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11462 | } |
| 11463 | return; |
| 11464 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11465 | |
| 11466 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11467 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11468 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11469 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11470 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11471 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11472 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11473 | |
| 11474 | boolean isVisible = false; |
| 11475 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11476 | if (am != null) { |
| 11477 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11478 | if (processes != null) { |
| 11479 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11480 | log("purchasePremiumCapability: process " + process.processName |
| 11481 | + "has importance " + process.importance); |
| 11482 | if (process.processName.equals(callingProcess) && process.importance |
| 11483 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11484 | isVisible = true; |
| 11485 | break; |
| 11486 | } |
| 11487 | } |
| 11488 | } |
| 11489 | } |
| 11490 | |
| 11491 | if (!isVisible) { |
| 11492 | try { |
| 11493 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11494 | callback.accept(result); |
| 11495 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11496 | } catch (RemoteException e) { |
| 11497 | String logStr = "Purchase premium capability " |
| 11498 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11499 | + " failed due to RemoteException handling background application: " + e; |
| 11500 | if (DBG) log(logStr); |
| 11501 | AnomalyReporter.reportAnomaly( |
| 11502 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11503 | } |
| 11504 | return; |
| 11505 | } |
| 11506 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11507 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame^] | 11508 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11509 | } |
| 11510 | |
| 11511 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11512 | * Register an IMS connection state callback |
| 11513 | */ |
| 11514 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11515 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11516 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11517 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11518 | // ImsMmTelManager |
| 11519 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11520 | TelephonyPermissions |
| 11521 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11522 | mApp, subId, "registerImsStateCallback"); |
| 11523 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11524 | // ImsRcsManager or SipDelegateManager |
| 11525 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11526 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11527 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11528 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11529 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11530 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11531 | } |
| 11532 | |
| 11533 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11534 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11535 | "IMS not available on device."); |
| 11536 | } |
| 11537 | |
| 11538 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11539 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11540 | } |
| 11541 | |
| 11542 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11543 | if (controller == null) { |
| 11544 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11545 | "IMS not available on device."); |
| 11546 | } |
| 11547 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11548 | if (callingPackage == null) { |
| 11549 | callingPackage = getCurrentPackageName(); |
| 11550 | } |
| 11551 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11552 | final long token = Binder.clearCallingIdentity(); |
| 11553 | try { |
| 11554 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11555 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11556 | } catch (ImsException e) { |
| 11557 | throw new ServiceSpecificException(e.getCode()); |
| 11558 | } finally { |
| 11559 | Binder.restoreCallingIdentity(token); |
| 11560 | } |
| 11561 | } |
| 11562 | |
| 11563 | /** |
| 11564 | * Unregister an IMS connection state callback |
| 11565 | */ |
| 11566 | @Override |
| 11567 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11568 | final long token = Binder.clearCallingIdentity(); |
| 11569 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11570 | if (controller == null) { |
| 11571 | return; |
| 11572 | } |
| 11573 | try { |
| 11574 | controller.unregisterImsStateCallback(cb); |
| 11575 | } finally { |
| 11576 | Binder.restoreCallingIdentity(token); |
| 11577 | } |
| 11578 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11579 | |
| 11580 | /** |
| 11581 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11582 | * |
| 11583 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11584 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11585 | * SecurityException. |
| 11586 | * If there is current registered network this value will be same as the registered cell |
| 11587 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11588 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11589 | * it will be cleared and null will be returned. |
| 11590 | * |
| 11591 | */ |
| 11592 | @Override |
| 11593 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11594 | String callingFeatureId) { |
| 11595 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11596 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11597 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11598 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11599 | .setCallingPackage(callingPackage) |
| 11600 | .setCallingFeatureId(callingFeatureId) |
| 11601 | .setCallingPid(Binder.getCallingPid()) |
| 11602 | .setCallingUid(Binder.getCallingUid()) |
| 11603 | .setMethod("getLastKnownCellIdentity") |
| 11604 | .setLogAsInfo(true) |
| 11605 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11606 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11607 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11608 | .build()); |
| 11609 | |
| 11610 | boolean hasFinePermission = |
| 11611 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11612 | if (!hasFinePermission |
| 11613 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11614 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11615 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11616 | } |
| 11617 | |
| 11618 | final long identity = Binder.clearCallingIdentity(); |
| 11619 | try { |
| 11620 | Phone phone = getPhone(subId); |
| 11621 | if (phone == null) return null; |
| 11622 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11623 | if (sst == null) return null; |
| 11624 | return sst.getLastKnownCellIdentity(); |
| 11625 | } finally { |
| 11626 | Binder.restoreCallingIdentity(identity); |
| 11627 | } |
| 11628 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11629 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11630 | /** |
| 11631 | * Sets the modem service class Name that Telephony will bind to. |
| 11632 | * |
| 11633 | * @param serviceName The class name of the modem service. |
| 11634 | * @return true if the operation is succeed, otherwise false. |
| 11635 | */ |
| 11636 | public boolean setModemService(String serviceName) { |
| 11637 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11638 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11640 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11641 | "setModemService"); |
| 11642 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11643 | } |
| 11644 | |
| 11645 | /** |
| 11646 | * Return the class name of the currently bounded modem service. |
| 11647 | * |
| 11648 | * @return the class name of the modem service. |
| 11649 | */ |
| 11650 | public String getModemService() { |
| 11651 | String result; |
| 11652 | Log.d(LOG_TAG, "getModemService"); |
| 11653 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11654 | TelephonyPermissions |
| 11655 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11656 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11657 | "getModemService"); |
| 11658 | result = mPhoneConfigurationManager.getModemService(); |
| 11659 | Log.d(LOG_TAG, "result = " + result); |
| 11660 | return result; |
| 11661 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11662 | |
| 11663 | @Override |
| 11664 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11665 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11666 | mApp.enforceCallingOrSelfPermission( |
| 11667 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11668 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11669 | |
| 11670 | final long identity = Binder.clearCallingIdentity(); |
| 11671 | try { |
| 11672 | Phone phone = getPhone(subId); |
| 11673 | if (phone == null) return; |
| 11674 | phone.setVoiceServiceStateOverride(hasService); |
| 11675 | } finally { |
| 11676 | Binder.restoreCallingIdentity(identity); |
| 11677 | } |
| 11678 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11679 | |
| 11680 | /** |
| 11681 | * set removable eSIM as default eUICC. |
| 11682 | * |
| 11683 | * @hide |
| 11684 | */ |
| 11685 | @Override |
| 11686 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11687 | enforceModifyPermission(); |
| 11688 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11689 | |
| 11690 | final long identity = Binder.clearCallingIdentity(); |
| 11691 | try { |
| 11692 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11693 | } finally { |
| 11694 | Binder.restoreCallingIdentity(identity); |
| 11695 | } |
| 11696 | } |
| 11697 | |
| 11698 | /** |
| 11699 | * Returns whether the removable eSIM is default eUICC or not. |
| 11700 | * |
| 11701 | * @hide |
| 11702 | */ |
| 11703 | @Override |
| 11704 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11705 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11707 | |
| 11708 | final long identity = Binder.clearCallingIdentity(); |
| 11709 | try { |
| 11710 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11711 | } finally { |
| 11712 | Binder.restoreCallingIdentity(identity); |
| 11713 | } |
| 11714 | } |
| 11715 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11716 | /** |
| 11717 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11718 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11719 | * application currently configured for this user. |
| 11720 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11721 | * {@code null} if the functionality is not supported. |
| 11722 | * @hide |
| 11723 | */ |
| 11724 | @Override |
| 11725 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11726 | boolean updateIfNeeded) { |
| 11727 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11728 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11729 | Context context = getPhone(subId).getContext(); |
| 11730 | UserHandle userHandle = null; |
| 11731 | final long identity = Binder.clearCallingIdentity(); |
| 11732 | try { |
| 11733 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11734 | } finally { |
| 11735 | Binder.restoreCallingIdentity(identity); |
| 11736 | } |
| 11737 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11738 | updateIfNeeded, userHandle); |
| 11739 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11740 | |
| 11741 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11742 | * Set whether the device is able to connect with null ciphering or integrity |
| 11743 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11744 | * and all new subscriptions after this. |
| 11745 | * |
| 11746 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11747 | * @hide |
| 11748 | */ |
| 11749 | @Override |
| 11750 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11751 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11752 | enforceModifyPermission(); |
| 11753 | checkForNullCipherAndIntegritySupport(); |
| 11754 | |
| 11755 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11756 | // for listening to these preference changes and applying them immediately. |
| 11757 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11758 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11759 | editor.apply(); |
| 11760 | |
| 11761 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11762 | phone.handleNullCipherEnabledChange(); |
| 11763 | } |
| 11764 | } |
| 11765 | |
| 11766 | |
| 11767 | /** |
| 11768 | * Get whether the device is able to connect with null ciphering or integrity |
| 11769 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11770 | * the state of the radio. |
| 11771 | * |
| 11772 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11773 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11774 | * version for this feature. |
| 11775 | * @hide |
| 11776 | */ |
| 11777 | @Override |
| 11778 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11779 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11780 | enforceReadPermission(); |
| 11781 | checkForNullCipherAndIntegritySupport(); |
| 11782 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11783 | } |
| 11784 | |
| 11785 | private void checkForNullCipherAndIntegritySupport() { |
| 11786 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11787 | throw new UnsupportedOperationException( |
| 11788 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11789 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11790 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11791 | throw new UnsupportedOperationException( |
| 11792 | "Null cipher and integrity operations unsupported by modem"); |
| 11793 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11794 | } |
| 11795 | |
| 11796 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11797 | * Get the SIM state for the slot index. |
| 11798 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11799 | * |
| 11800 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11801 | */ |
| 11802 | @Override |
| 11803 | @SimState |
| 11804 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11805 | IccCardConstants.State simState; |
| 11806 | if (slotIndex < 0) { |
| 11807 | simState = IccCardConstants.State.UNKNOWN; |
| 11808 | } else { |
| 11809 | Phone phone = null; |
| 11810 | try { |
| 11811 | phone = PhoneFactory.getPhone(slotIndex); |
| 11812 | } catch (IllegalStateException e) { |
| 11813 | // ignore |
| 11814 | } |
| 11815 | if (phone == null) { |
| 11816 | simState = IccCardConstants.State.UNKNOWN; |
| 11817 | } else { |
| 11818 | IccCard icc = phone.getIccCard(); |
| 11819 | if (icc == null) { |
| 11820 | simState = IccCardConstants.State.UNKNOWN; |
| 11821 | } else { |
| 11822 | simState = icc.getState(); |
| 11823 | } |
| 11824 | } |
| 11825 | } |
| 11826 | return simState.ordinal(); |
| 11827 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 11828 | |
| 11829 | /** |
| 11830 | * Get current cell broadcast ranges. |
| 11831 | */ |
| 11832 | @Override |
| 11833 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11834 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 11835 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11836 | "getCellBroadcastIdRanges"); |
| 11837 | final long identity = Binder.clearCallingIdentity(); |
| 11838 | try { |
| 11839 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 11840 | } finally { |
| 11841 | Binder.restoreCallingIdentity(identity); |
| 11842 | } |
| 11843 | } |
| 11844 | |
| 11845 | /** |
| 11846 | * Set reception of cell broadcast messages with the list of the given ranges |
| 11847 | * |
| 11848 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 11849 | */ |
| 11850 | @Override |
| 11851 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 11852 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 11853 | @Nullable IIntegerConsumer callback) { |
| 11854 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 11855 | "setCellBroadcastIdRanges"); |
| 11856 | final long identity = Binder.clearCallingIdentity(); |
| 11857 | try { |
| 11858 | Phone phone = getPhoneFromSubId(subId); |
| 11859 | if (DBG) { |
| 11860 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 11861 | } |
| 11862 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 11863 | if (callback != null) { |
| 11864 | try { |
| 11865 | callback.accept(result); |
| 11866 | } catch (RemoteException e) { |
| 11867 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 11868 | } |
| 11869 | } |
| 11870 | }); |
| 11871 | } finally { |
| 11872 | Binder.restoreCallingIdentity(identity); |
| 11873 | } |
| 11874 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 11875 | |
| 11876 | /** |
| 11877 | * Returns whether the device supports the domain selection service. |
| 11878 | * |
| 11879 | * @return {@code true} if the device supports the domain selection service. |
| 11880 | */ |
| 11881 | @Override |
| 11882 | public boolean isDomainSelectionSupported() { |
| 11883 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11884 | "isDomainSelectionSupported"); |
| 11885 | |
| 11886 | final long identity = Binder.clearCallingIdentity(); |
| 11887 | try { |
| 11888 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 11889 | } finally { |
| 11890 | Binder.restoreCallingIdentity(identity); |
| 11891 | } |
| 11892 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 11893 | |
| 11894 | /** |
| 11895 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 11896 | * |
| 11897 | * <p>This method behaves in one of the following ways: |
| 11898 | * <ul> |
| 11899 | * <li>return true : if the calling package has the appop permission {@link |
| 11900 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 11901 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 11902 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 11903 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 11904 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 11905 | * </ul> |
| 11906 | */ |
| 11907 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 11908 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 11909 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11910 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 11911 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 11912 | return true; |
| 11913 | } |
| 11914 | } |
| 11915 | return false; |
| 11916 | } |
| 11917 | } |