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 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS; |
| 20 | import static android.content.pm.PackageManager.FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Nate Myren | ae97d19 | 2023-06-09 15:22:31 -0700 | [diff] [blame] | 22 | import static android.permission.flags.Flags.opEnableMobileDataByUser; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 23 | import static android.telephony.TelephonyManager.ENABLE_FEATURE_MAPPING; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 24 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 25 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 26 | import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED; |
| 27 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_ACCESS_BARRED; |
| 28 | import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 29 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 30 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 31 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 32 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 33 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 34 | 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] | 35 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 36 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 37 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 38 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 39 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 41 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 43 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 44 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 45 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 46 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 47 | import android.compat.annotation.ChangeId; |
| 48 | import android.compat.annotation.EnabledSince; |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 49 | import android.content.ActivityNotFoundException; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 50 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 51 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.content.Context; |
| 53 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 54 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 55 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 56 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.net.Uri; |
| 58 | import android.os.AsyncResult; |
| 59 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 60 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 62 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 64 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 65 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 66 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | import android.os.Looper; |
| 68 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 69 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 70 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 71 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 72 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 73 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 74 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 75 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 76 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 77 | import android.os.SystemClock; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 78 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 80 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 82 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 83 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 84 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 85 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 86 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 87 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 88 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 89 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 90 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 91 | import android.telephony.AccessNetworkConstants; |
| 92 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 93 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 94 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 95 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 96 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 97 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 98 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 99 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 100 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 101 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 102 | import android.telephony.CellIdentityCdma; |
| 103 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 105 | import android.telephony.CellInfoGsm; |
| 106 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 107 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 108 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 110 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 111 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 112 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 113 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 114 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 115 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 116 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 117 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 118 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 119 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 121 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 122 | import android.telephony.SignalStrengthUpdateRequest; |
| 123 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 124 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 126 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 127 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 129 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 130 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 131 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 132 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 133 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 134 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 135 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 136 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 137 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 138 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 139 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 140 | import android.telephony.gba.GbaAuthRequest; |
| 141 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 142 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 143 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 145 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 146 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 147 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 148 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 149 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 150 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 151 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 152 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 153 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 154 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 155 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 156 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 157 | import android.telephony.satellite.INtnSignalStrengthCallback; |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 158 | import android.telephony.satellite.ISatelliteCapabilitiesCallback; |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 159 | import android.telephony.satellite.ISatelliteCommunicationAllowedStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 160 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 161 | import android.telephony.satellite.ISatelliteModemStateCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 162 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 163 | import android.telephony.satellite.ISatelliteSupportedStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 164 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 165 | import android.telephony.satellite.NtnSignalStrength; |
| 166 | import android.telephony.satellite.NtnSignalStrengthCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 167 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 168 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 169 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 170 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 171 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 172 | import android.telephony.satellite.SatelliteSubscriberInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 175 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 178 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 179 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 180 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 181 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 182 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 197 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 214 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 216 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 217 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 218 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.SmsPermissions; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 220 | import com.android.internal.telephony.TelephonyCountryDetector; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 221 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 224 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.euicc.EuiccConnector; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 227 | import com.android.internal.telephony.flags.FeatureFlags; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 229 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 230 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 231 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 232 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 233 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 234 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 235 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 236 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 237 | import com.android.internal.telephony.uicc.IccIoResult; |
| 238 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 239 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 240 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 241 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 242 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 243 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 244 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 245 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 246 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 247 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 248 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 249 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 250 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 251 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 252 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 253 | import com.android.phone.callcomposer.ImageData; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 254 | import com.android.phone.satellite.accesscontrol.SatelliteAccessController; |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 255 | import com.android.phone.satellite.entitlement.SatelliteEntitlementController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 256 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 257 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 258 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 259 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 260 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 261 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 262 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 263 | import com.android.server.feature.flags.Flags; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 264 | import com.android.services.telephony.TelecomAccountRegistry; |
| 265 | import com.android.services.telephony.TelephonyConnectionService; |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 266 | import com.android.services.telephony.domainselection.TelephonyDomainSelectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 267 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 268 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 269 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 270 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 271 | import java.io.IOException; |
| 272 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 273 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 275 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 276 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 277 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 278 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 279 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 280 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 281 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 282 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 283 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 284 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 285 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 286 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 287 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 288 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 289 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * Implementation of the ITelephony interface. |
| 293 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 294 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 296 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 297 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 298 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | |
| 300 | // Message codes used with mMainThreadHandler |
| 301 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 302 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 303 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 304 | private static final int CMD_OPEN_CHANNEL = 9; |
| 305 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 306 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 307 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 308 | private static final int CMD_NV_READ_ITEM = 13; |
| 309 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 310 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 311 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 312 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 313 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 314 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 315 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 316 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 317 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 318 | private static final int CMD_SEND_ENVELOPE = 25; |
| 319 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 320 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 321 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 322 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 323 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 325 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 326 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 327 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 328 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 329 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 330 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 331 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 332 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 333 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 334 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 335 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 336 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 337 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 338 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 339 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 340 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 341 | private static final int CMD_SWITCH_SLOTS = 50; |
| 342 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 343 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 344 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 345 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 346 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 347 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 348 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 349 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 350 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 351 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 352 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 353 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 354 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 355 | private static final int CMD_MODEM_REBOOT = 64; |
| 356 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 357 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 358 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 359 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 360 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 361 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 362 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 363 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 364 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 365 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 366 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 367 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 368 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 369 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 370 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 371 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 372 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 373 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 374 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 375 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 376 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 377 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 378 | private static final int CMD_GET_CALL_WAITING = 87; |
| 379 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 380 | private static final int CMD_SET_CALL_WAITING = 89; |
| 381 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 382 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 383 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 384 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 385 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 386 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 387 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 388 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 389 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 390 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 391 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 392 | private static final int CMD_SET_SIM_POWER = 101; |
| 393 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 394 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 395 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 396 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 397 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 398 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 399 | 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] | 400 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 401 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 402 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 403 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 404 | private static final int CMD_ENABLE_VONR = 113; |
| 405 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 406 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 407 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 408 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 409 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 410 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 411 | // Parameters of select command. |
| 412 | private static final int SELECT_COMMAND = 0xA4; |
| 413 | private static final int SELECT_P1 = 0x04; |
| 414 | private static final int SELECT_P2 = 0; |
| 415 | private static final int SELECT_P3 = 0x10; |
| 416 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 417 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 418 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 419 | // Cellular identifier disclosure transparency was added in IRadioNetwork 2.2 |
| 420 | private static final int MIN_IDENTIFIER_DISCLOSURE_VERSION = 202; |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 421 | // Null cipher notification support was added in IRadioNetwork 2.2 |
| 422 | private static final int MIN_NULL_CIPHER_NOTIFICATION_VERSION = 202; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 423 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | /** The singleton instance. */ |
| 425 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 426 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 428 | private final PhoneGlobals mApp; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 429 | private FeatureFlags mFeatureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 430 | private com.android.server.telecom.flags.FeatureFlags mTelecomFeatureFlags; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 431 | private final CallManager mCM; |
| 432 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 433 | |
| 434 | private final SatelliteController mSatelliteController; |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 435 | private final SatelliteAccessController mSatelliteAccessController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 436 | private final UserManager mUserManager; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 437 | private final MainThreadHandler mMainThreadHandler; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 438 | private final SharedPreferences mTelephonySharedPreferences; |
| 439 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 440 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 441 | private AppOpsManager mAppOps; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 442 | private PackageManager mPackageManager; |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 443 | private final int mVendorApiLevel; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 445 | @Nullable |
| 446 | private ComponentName mTestEuiccUiComponent; |
| 447 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 448 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 449 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 450 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 451 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 452 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 453 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 454 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 455 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 456 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 457 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 458 | // String to store multi SIM allowed |
| 459 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 460 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 461 | // The AID of ISD-R. |
| 462 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 463 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 464 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 465 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 466 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 467 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 468 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 469 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 470 | 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] | 471 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 472 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 473 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 474 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 475 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 476 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 477 | */ |
| 478 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 479 | "reset_network_erase_modem_config_enabled"; |
| 480 | |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 481 | private static final int BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 482 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 483 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 484 | |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 485 | private static final int LINE1_NUMBER_MAX_LEN = 50; |
| 486 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 487 | /** |
| 488 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 489 | * one ICCID active at the same time. |
| 490 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 491 | * |
| 492 | * @hide |
| 493 | */ |
| 494 | @ChangeId |
| 495 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 496 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 497 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 498 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 499 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 500 | * operation fails. |
| 501 | */ |
| 502 | @ChangeId |
| 503 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 504 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 505 | |
| 506 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 507 | * A request object to use for transmitting data to an ICC. |
| 508 | */ |
| 509 | private static final class IccAPDUArgument { |
| 510 | public int channel, cla, command, p1, p2, p3; |
| 511 | public String data; |
| 512 | |
| 513 | public IccAPDUArgument(int channel, int cla, int command, |
| 514 | int p1, int p2, int p3, String data) { |
| 515 | this.channel = channel; |
| 516 | this.cla = cla; |
| 517 | this.command = command; |
| 518 | this.p1 = p1; |
| 519 | this.p2 = p2; |
| 520 | this.p3 = p3; |
| 521 | this.data = data; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 526 | * A request object to use for transmitting data to an ICC. |
| 527 | */ |
| 528 | private static final class ManualNetworkSelectionArgument { |
| 529 | public OperatorInfo operatorInfo; |
| 530 | public boolean persistSelection; |
| 531 | |
| 532 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 533 | this.operatorInfo = operatorInfo; |
| 534 | this.persistSelection = persistSelection; |
| 535 | } |
| 536 | } |
| 537 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 538 | private static final class PurchasePremiumCapabilityArgument { |
| 539 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 540 | public @NonNull IIntegerConsumer callback; |
| 541 | |
| 542 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 543 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 544 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 545 | this.callback = callback; |
| 546 | } |
| 547 | } |
| 548 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 549 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 550 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 551 | * request after sending. The main thread will notify the request when it is complete. |
| 552 | */ |
| 553 | private static final class MainThreadRequest { |
| 554 | /** The argument to use for the request */ |
| 555 | public Object argument; |
| 556 | /** The result of the request that is run on the main thread */ |
| 557 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 558 | // The subscriber id that this request applies to. Defaults to |
| 559 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 560 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 561 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 562 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 563 | public Phone phone; |
| 564 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 565 | public WorkSource workSource; |
| 566 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 567 | public MainThreadRequest(Object argument) { |
| 568 | this.argument = argument; |
| 569 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 570 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 571 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 572 | this.argument = argument; |
| 573 | if (phone != null) { |
| 574 | this.phone = phone; |
| 575 | } |
| 576 | this.workSource = workSource; |
| 577 | } |
| 578 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 579 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 580 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 581 | if (subId != null) { |
| 582 | this.subId = subId; |
| 583 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 584 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 585 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 588 | private static final class IncomingThirdPartyCallArgs { |
| 589 | public final ComponentName component; |
| 590 | public final String callId; |
| 591 | public final String callerDisplayName; |
| 592 | |
| 593 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 594 | String callerDisplayName) { |
| 595 | this.component = component; |
| 596 | this.callId = callId; |
| 597 | this.callerDisplayName = callerDisplayName; |
| 598 | } |
| 599 | } |
| 600 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 601 | /** |
| 602 | * A handler that processes messages on the main thread in the phone process. Since many |
| 603 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 604 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 605 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 606 | * on, which will be notified when the operation completes and will contain the result of the |
| 607 | * request. |
| 608 | * |
| 609 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 610 | * note that request.result must be set to something non-null for the calling thread to |
| 611 | * unblock. |
| 612 | */ |
| 613 | private final class MainThreadHandler extends Handler { |
| 614 | @Override |
| 615 | public void handleMessage(Message msg) { |
| 616 | MainThreadRequest request; |
| 617 | Message onCompleted; |
| 618 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 619 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 621 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 622 | |
| 623 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | case CMD_HANDLE_USSD_REQUEST: { |
| 625 | request = (MainThreadRequest) msg.obj; |
| 626 | final Phone phone = getPhoneFromRequest(request); |
| 627 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 628 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 630 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 631 | if (!isUssdApiAllowed(request.subId)) { |
| 632 | // Carrier does not support use of this API, return failure. |
| 633 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 634 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 635 | Bundle returnData = new Bundle(); |
| 636 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 637 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 638 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | request.result = true; |
| 640 | notifyRequester(request); |
| 641 | return; |
| 642 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 643 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | try { |
| 645 | request.result = phone != null |
| 646 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 647 | } catch (CallStateException cse) { |
| 648 | request.result = false; |
| 649 | } |
| 650 | // Wake up the requesting thread |
| 651 | notifyRequester(request); |
| 652 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 655 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 656 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 657 | final Phone phone = getPhoneFromRequest(request); |
| 658 | request.result = phone != null ? |
| 659 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 660 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 663 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 664 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 665 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 669 | uiccPort = getUiccPortFromRequest(request); |
| 670 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 671 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 672 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 674 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 675 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 676 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 677 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 678 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 679 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 680 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 681 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | break; |
| 683 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | ar = (AsyncResult) msg.obj; |
| 686 | request = (MainThreadRequest) ar.userObj; |
| 687 | if (ar.exception == null && ar.result != null) { |
| 688 | request.result = ar.result; |
| 689 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 690 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | if (ar.result == null) { |
| 692 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 693 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | } else { |
| 697 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 698 | } |
| 699 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | break; |
| 702 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 704 | request = (MainThreadRequest) msg.obj; |
| 705 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 706 | uiccPort = getUiccPortFromRequest(request); |
| 707 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 709 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 711 | } else { |
| 712 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 713 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 714 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 715 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 716 | iccArgument.p2, |
| 717 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | } |
| 719 | break; |
| 720 | |
| 721 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 722 | ar = (AsyncResult) msg.obj; |
| 723 | request = (MainThreadRequest) ar.userObj; |
| 724 | if (ar.exception == null && ar.result != null) { |
| 725 | request.result = ar.result; |
| 726 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 727 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 728 | if (ar.result == null) { |
| 729 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 730 | } else if (ar.exception instanceof CommandException) { |
| 731 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 732 | ar.exception); |
| 733 | } else { |
| 734 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 735 | } |
| 736 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 737 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case CMD_EXCHANGE_SIM_IO: |
| 741 | request = (MainThreadRequest) msg.obj; |
| 742 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 743 | uiccPort = getUiccPortFromRequest(request); |
| 744 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 745 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 746 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 747 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 748 | } else { |
| 749 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 750 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 751 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 752 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 753 | iccArgument.data, onCompleted); |
| 754 | } |
| 755 | break; |
| 756 | |
| 757 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 758 | ar = (AsyncResult) msg.obj; |
| 759 | request = (MainThreadRequest) ar.userObj; |
| 760 | if (ar.exception == null && ar.result != null) { |
| 761 | request.result = ar.result; |
| 762 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 763 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 764 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 765 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 766 | break; |
| 767 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 768 | case CMD_SEND_ENVELOPE: |
| 769 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 770 | uiccPort = getUiccPortFromRequest(request); |
| 771 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 772 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 773 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 774 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 775 | } else { |
| 776 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 777 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 778 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case EVENT_SEND_ENVELOPE_DONE: |
| 782 | ar = (AsyncResult) msg.obj; |
| 783 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 784 | if (ar.exception == null && ar.result != null) { |
| 785 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 786 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 787 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 788 | if (ar.result == null) { |
| 789 | loge("sendEnvelopeWithStatus: Empty response"); |
| 790 | } else if (ar.exception instanceof CommandException) { |
| 791 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 792 | ar.exception); |
| 793 | } else { |
| 794 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 795 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 796 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 797 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 798 | break; |
| 799 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 800 | case CMD_OPEN_CHANNEL: |
| 801 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 802 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 803 | IccLogicalChannelRequest openChannelRequest = |
| 804 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 805 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 806 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 807 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 808 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 809 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 810 | } else { |
| 811 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 812 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 813 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 814 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 815 | break; |
| 816 | |
| 817 | case EVENT_OPEN_CHANNEL_DONE: |
| 818 | ar = (AsyncResult) msg.obj; |
| 819 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 820 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 821 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 822 | int[] result = (int[]) ar.result; |
| 823 | int channelId = result[0]; |
| 824 | byte[] selectResponse = null; |
| 825 | if (result.length > 1) { |
| 826 | selectResponse = new byte[result.length - 1]; |
| 827 | for (int i = 1; i < result.length; ++i) { |
| 828 | selectResponse[i - 1] = (byte) result[i]; |
| 829 | } |
| 830 | } |
| 831 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 832 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 833 | |
| 834 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 835 | if (uiccPort == null) { |
| 836 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 837 | } else { |
| 838 | IccLogicalChannelRequest channelRequest = |
| 839 | (IccLogicalChannelRequest) request.argument; |
| 840 | channelRequest.channel = channelId; |
| 841 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 842 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 843 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 844 | if (ar.result == null) { |
| 845 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 846 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 847 | if (ar.exception != null) { |
| 848 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 849 | } |
| 850 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 851 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 852 | if (ar.exception instanceof CommandException) { |
| 853 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 854 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 855 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 856 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 857 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 858 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 862 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 863 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 864 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 865 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 866 | break; |
| 867 | |
| 868 | case CMD_CLOSE_CHANNEL: |
| 869 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 870 | uiccPort = getUiccPortFromRequest(request); |
| 871 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 872 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 873 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 874 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 875 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 876 | } else { |
| 877 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 878 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 879 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 883 | ar = (AsyncResult) msg.obj; |
| 884 | request = (MainThreadRequest) ar.userObj; |
| 885 | if (ar.exception == null) { |
| 886 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 887 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 888 | if (uiccPort == null) { |
| 889 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 890 | } else { |
| 891 | final int channelId = (Integer) request.argument; |
| 892 | uiccPort.onLogicalChannelClosed(channelId); |
| 893 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 894 | } else { |
| 895 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 896 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 897 | if (ar.exception instanceof CommandException) { |
| 898 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 899 | CommandException.Error error = |
| 900 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 901 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 902 | // should only throw exceptions from the binder threads. |
| 903 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 904 | "iccCloseLogicalChannel: invalid argument "); |
| 905 | } |
| 906 | } else { |
| 907 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 908 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 909 | request.result = (exception != null) ? exception : |
| 910 | new IllegalStateException( |
| 911 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 912 | } |
| 913 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case CMD_NV_READ_ITEM: |
| 917 | request = (MainThreadRequest) msg.obj; |
| 918 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 919 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 920 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 924 | ar = (AsyncResult) msg.obj; |
| 925 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 926 | if (ar.exception == null && ar.result != null) { |
| 927 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 928 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 929 | request.result = ""; |
| 930 | if (ar.result == null) { |
| 931 | loge("nvReadItem: Empty response"); |
| 932 | } else if (ar.exception instanceof CommandException) { |
| 933 | loge("nvReadItem: CommandException: " + |
| 934 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 935 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 936 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 937 | } |
| 938 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 939 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 940 | break; |
| 941 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 942 | case CMD_NV_WRITE_ITEM: |
| 943 | request = (MainThreadRequest) msg.obj; |
| 944 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 945 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 946 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 947 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 948 | break; |
| 949 | |
| 950 | case EVENT_NV_WRITE_ITEM_DONE: |
| 951 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 952 | break; |
| 953 | |
| 954 | case CMD_NV_WRITE_CDMA_PRL: |
| 955 | request = (MainThreadRequest) msg.obj; |
| 956 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 957 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 958 | break; |
| 959 | |
| 960 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 961 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 962 | break; |
| 963 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 964 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 965 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 966 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 967 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 968 | break; |
| 969 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 970 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 971 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 972 | break; |
| 973 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 974 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 975 | request = (MainThreadRequest) msg.obj; |
| 976 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 977 | request); |
| 978 | Phone phone = getPhoneFromRequest(request); |
| 979 | if (phone != null) { |
| 980 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 981 | } else { |
| 982 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 983 | request.result = false; |
| 984 | notifyRequester(request); |
| 985 | } |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 990 | ar = (AsyncResult) msg.obj; |
| 991 | request = (MainThreadRequest) ar.userObj; |
| 992 | if (ar.exception == null && ar.result != null) { |
| 993 | request.result = ar.result; |
| 994 | } else { |
| 995 | // request.result must be set to something non-null |
| 996 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 997 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 998 | request.result = ar.result; |
| 999 | } else { |
| 1000 | request.result = false; |
| 1001 | } |
| 1002 | if (ar.result == null) { |
| 1003 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 1004 | } else if (ar.exception instanceof CommandException) { |
| 1005 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 1006 | + ar.exception); |
| 1007 | } else { |
| 1008 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 1009 | } |
| 1010 | } |
| 1011 | notifyRequester(request); |
| 1012 | break; |
| 1013 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1014 | case CMD_IS_VONR_ENABLED: { |
| 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 1017 | request); |
| 1018 | Phone phone = getPhoneFromRequest(request); |
| 1019 | if (phone != null) { |
| 1020 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 1021 | } else { |
| 1022 | loge("isVoNrEnabled: No phone object"); |
| 1023 | request.result = false; |
| 1024 | notifyRequester(request); |
| 1025 | } |
| 1026 | break; |
| 1027 | } |
| 1028 | |
| 1029 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1030 | ar = (AsyncResult) msg.obj; |
| 1031 | request = (MainThreadRequest) ar.userObj; |
| 1032 | if (ar.exception == null && ar.result != null) { |
| 1033 | request.result = ar.result; |
| 1034 | } else { |
| 1035 | // request.result must be set to something non-null |
| 1036 | // for the calling thread to unblock |
| 1037 | if (ar.result != null) { |
| 1038 | request.result = ar.result; |
| 1039 | } else { |
| 1040 | request.result = false; |
| 1041 | } |
| 1042 | if (ar.result == null) { |
| 1043 | loge("isVoNrEnabled: Empty response"); |
| 1044 | } else if (ar.exception instanceof CommandException) { |
| 1045 | loge("isVoNrEnabled: CommandException: " |
| 1046 | + ar.exception); |
| 1047 | } else { |
| 1048 | loge("isVoNrEnabled: Unknown exception"); |
| 1049 | } |
| 1050 | } |
| 1051 | notifyRequester(request); |
| 1052 | break; |
| 1053 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1054 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1055 | request = (MainThreadRequest) msg.obj; |
| 1056 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1057 | Phone phone = getPhoneFromRequest(request); |
| 1058 | if (phone != null) { |
| 1059 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1060 | request.workSource); |
| 1061 | } else { |
| 1062 | loge("enableNrDualConnectivity: No phone object"); |
| 1063 | request.result = |
| 1064 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1065 | notifyRequester(request); |
| 1066 | } |
| 1067 | break; |
| 1068 | } |
| 1069 | |
| 1070 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1071 | ar = (AsyncResult) msg.obj; |
| 1072 | request = (MainThreadRequest) ar.userObj; |
| 1073 | if (ar.exception == null) { |
| 1074 | request.result = |
| 1075 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1076 | } else { |
| 1077 | request.result = |
| 1078 | TelephonyManager |
| 1079 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1080 | if (ar.exception instanceof CommandException) { |
| 1081 | CommandException.Error error = |
| 1082 | ((CommandException) (ar.exception)).getCommandError(); |
| 1083 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1084 | request.result = |
| 1085 | TelephonyManager |
| 1086 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1087 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1088 | request.result = |
| 1089 | TelephonyManager |
| 1090 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1091 | } |
| 1092 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1093 | + ar.exception); |
| 1094 | } else { |
| 1095 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1096 | } |
| 1097 | } |
| 1098 | notifyRequester(request); |
| 1099 | break; |
| 1100 | } |
| 1101 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1102 | case CMD_ENABLE_VONR: { |
| 1103 | request = (MainThreadRequest) msg.obj; |
| 1104 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1105 | Phone phone = getPhoneFromRequest(request); |
| 1106 | if (phone != null) { |
| 1107 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1108 | request.workSource); |
| 1109 | } else { |
| 1110 | loge("setVoNrEnabled: No phone object"); |
| 1111 | request.result = |
| 1112 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1113 | notifyRequester(request); |
| 1114 | } |
| 1115 | break; |
| 1116 | } |
| 1117 | |
| 1118 | case EVENT_ENABLE_VONR_DONE: { |
| 1119 | ar = (AsyncResult) msg.obj; |
| 1120 | request = (MainThreadRequest) ar.userObj; |
| 1121 | if (ar.exception == null) { |
| 1122 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1123 | } else { |
| 1124 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1125 | if (ar.exception instanceof CommandException) { |
| 1126 | CommandException.Error error = |
| 1127 | ((CommandException) (ar.exception)).getCommandError(); |
| 1128 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1129 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1130 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1131 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1132 | } else { |
| 1133 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1134 | } |
| 1135 | loge("setVoNrEnabled" + ": CommandException: " |
| 1136 | + ar.exception); |
| 1137 | } else { |
| 1138 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1139 | } |
| 1140 | } |
| 1141 | notifyRequester(request); |
| 1142 | break; |
| 1143 | } |
| 1144 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1145 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1146 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1147 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1148 | request); |
| 1149 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1150 | break; |
| 1151 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1152 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1153 | ar = (AsyncResult) msg.obj; |
| 1154 | request = (MainThreadRequest) ar.userObj; |
| 1155 | if (ar.exception == null && ar.result != null) { |
| 1156 | request.result = ar.result; // Integer |
| 1157 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1158 | // request.result must be set to something non-null |
| 1159 | // for the calling thread to unblock |
| 1160 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1161 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1162 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1163 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1164 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1165 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1166 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1167 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1168 | } |
| 1169 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1170 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1171 | break; |
| 1172 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1173 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1174 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1175 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1176 | request); |
| 1177 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1178 | (Pair<Integer, Long>) request.argument; |
| 1179 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1180 | reasonWithNetworkTypes.first, |
| 1181 | reasonWithNetworkTypes.second, |
| 1182 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1183 | break; |
| 1184 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1185 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1186 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1187 | break; |
| 1188 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1189 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1192 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1193 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1194 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1195 | break; |
| 1196 | |
| 1197 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1198 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1199 | break; |
| 1200 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1201 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1204 | request); |
| 1205 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1206 | break; |
| 1207 | |
| 1208 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1209 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1210 | break; |
| 1211 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1212 | case CMD_PERFORM_NETWORK_SCAN: |
| 1213 | request = (MainThreadRequest) msg.obj; |
| 1214 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1215 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1216 | break; |
| 1217 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | request = (MainThreadRequest) msg.obj; |
| 1220 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1221 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1222 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1223 | request.argument; |
| 1224 | int callForwardingReason = args.first; |
| 1225 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | } |
| 1228 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1229 | ar = (AsyncResult) msg.obj; |
| 1230 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1232 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1233 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1236 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1237 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1238 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1239 | // any service for voice call. |
| 1240 | if ((callForwardInfo.serviceClass |
| 1241 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1242 | callForwardingInfo = new CallForwardingInfo( |
| 1243 | callForwardInfo.status |
| 1244 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | callForwardInfo.reason, |
| 1246 | callForwardInfo.number, |
| 1247 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | // Didn't find a call forward info for voice call. |
| 1252 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1254 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1256 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | } else { |
| 1258 | if (ar.result == null) { |
| 1259 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1260 | } |
| 1261 | if (ar.exception != null) { |
| 1262 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1263 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1264 | int errorCode = TelephonyManager |
| 1265 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | if (ar.exception instanceof CommandException) { |
| 1267 | CommandException.Error error = |
| 1268 | ((CommandException) (ar.exception)).getCommandError(); |
| 1269 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1270 | errorCode = TelephonyManager |
| 1271 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1273 | errorCode = TelephonyManager |
| 1274 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | } |
| 1276 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | request = (MainThreadRequest) msg.obj; |
| 1284 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1288 | request.argument).first; |
| 1289 | request.phone.setCallForwardingOption( |
| 1290 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1291 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1293 | callForwardingInfoToSet.getReason(), |
| 1294 | callForwardingInfoToSet.getNumber(), |
| 1295 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1296 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | ar = (AsyncResult) msg.obj; |
| 1301 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | Consumer<Integer> callback = |
| 1303 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1304 | request.argument).second; |
| 1305 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1307 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1308 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | if (ar.exception instanceof CommandException) { |
| 1310 | CommandException.Error error = |
| 1311 | ((CommandException) (ar.exception)).getCommandError(); |
| 1312 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1313 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1314 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1316 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1317 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | callback.accept(errorCode); |
| 1321 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1322 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1326 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1327 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | request = (MainThreadRequest) msg.obj; |
| 1329 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1330 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1331 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | ar = (AsyncResult) msg.obj; |
| 1336 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1337 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1338 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1340 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | // Service Class is a bit mask per 3gpp 27.007. |
| 1342 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1343 | if (callForwardResults.length > 1 |
| 1344 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1345 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1346 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1348 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1349 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1350 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | } |
| 1352 | } else { |
| 1353 | if (ar.result == null) { |
| 1354 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1355 | } |
| 1356 | if (ar.exception != null) { |
| 1357 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1358 | } |
| 1359 | if (ar.exception instanceof CommandException) { |
| 1360 | CommandException.Error error = |
| 1361 | ((CommandException) (ar.exception)).getCommandError(); |
| 1362 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1363 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1365 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1366 | callWaitingStatus = |
| 1367 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1371 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1373 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1374 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1375 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1376 | request = (MainThreadRequest) msg.obj; |
| 1377 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1378 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1379 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1380 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1381 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1382 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1383 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1384 | ar = (AsyncResult) msg.obj; |
| 1385 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1386 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1387 | Consumer<Integer> callback = |
| 1388 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1389 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1390 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1391 | if (ar.exception instanceof CommandException) { |
| 1392 | CommandException.Error error = |
| 1393 | ((CommandException) (ar.exception)).getCommandError(); |
| 1394 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1395 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1396 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1397 | callback.accept( |
| 1398 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1399 | } else { |
| 1400 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1401 | } |
| 1402 | } else { |
| 1403 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1404 | } |
| 1405 | } else { |
| 1406 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1407 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1408 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1409 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1410 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1411 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1412 | ar = (AsyncResult) msg.obj; |
| 1413 | request = (MainThreadRequest) ar.userObj; |
| 1414 | CellNetworkScanResult cellScanResult; |
| 1415 | if (ar.exception == null && ar.result != null) { |
| 1416 | cellScanResult = new CellNetworkScanResult( |
| 1417 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1418 | (List<OperatorInfo>) ar.result); |
| 1419 | } else { |
| 1420 | if (ar.result == null) { |
| 1421 | loge("getCellNetworkScanResults: Empty response"); |
| 1422 | } |
| 1423 | if (ar.exception != null) { |
| 1424 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1425 | } |
| 1426 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1427 | if (ar.exception instanceof CommandException) { |
| 1428 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1429 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1430 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1431 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1432 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1433 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1434 | } |
| 1435 | } |
| 1436 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1437 | } |
| 1438 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1439 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1440 | break; |
| 1441 | |
| 1442 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1443 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1444 | ManualNetworkSelectionArgument selArg = |
| 1445 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1446 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1447 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1448 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1449 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1450 | break; |
| 1451 | |
| 1452 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1453 | ar = (AsyncResult) msg.obj; |
| 1454 | request = (MainThreadRequest) ar.userObj; |
| 1455 | if (ar.exception == null) { |
| 1456 | request.result = true; |
| 1457 | } else { |
| 1458 | request.result = false; |
| 1459 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1460 | } |
| 1461 | notifyRequester(request); |
| 1462 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1463 | break; |
| 1464 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1465 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1466 | request = (MainThreadRequest) msg.obj; |
| 1467 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1468 | if (defaultPhone != null) { |
| 1469 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1470 | } else { |
| 1471 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1472 | Bundle bundle = new Bundle(); |
| 1473 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1474 | new ModemActivityInfo(0, 0, 0, |
| 1475 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1476 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1477 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1478 | break; |
| 1479 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1480 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1481 | ar = (AsyncResult) msg.obj; |
| 1482 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1483 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1484 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1485 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1486 | if (mLastModemActivityInfo == null) { |
| 1487 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1488 | mLastModemActivitySpecificInfo[0] = |
| 1489 | new ActivityStatsTechSpecificInfo( |
| 1490 | 0, |
| 1491 | 0, |
| 1492 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1493 | 0); |
| 1494 | mLastModemActivityInfo = |
| 1495 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1496 | } |
| 1497 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1498 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1499 | // Update the last modem activity info and the result of the request. |
| 1500 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1501 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1502 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1503 | } else { |
| 1504 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1505 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1506 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1507 | // We don't want to return mLastModemActivityInfo which is updated |
| 1508 | // inside mergeModemActivityInfo() |
| 1509 | ret = new ModemActivityInfo( |
| 1510 | mLastModemActivityInfo.getTimestampMillis(), |
| 1511 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1512 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1513 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1514 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1515 | } else { |
| 1516 | if (ar.result == null) { |
| 1517 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1518 | error = TelephonyManager.ModemActivityInfoException |
| 1519 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1520 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1521 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1522 | error = TelephonyManager.ModemActivityInfoException |
| 1523 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1524 | } else { |
| 1525 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1526 | error = TelephonyManager.ModemActivityInfoException |
| 1527 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1530 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1531 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1532 | bundle.putParcelable( |
| 1533 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1534 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1535 | } else { |
| 1536 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1537 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1538 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1539 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1540 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1541 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1542 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1543 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1544 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1545 | CarrierRestrictionRules argument = |
| 1546 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1547 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1548 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1550 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1551 | |
| 1552 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1553 | ar = (AsyncResult) msg.obj; |
| 1554 | request = (MainThreadRequest) ar.userObj; |
| 1555 | if (ar.exception == null && ar.result != null) { |
| 1556 | request.result = ar.result; |
| 1557 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1558 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1559 | if (ar.exception instanceof CommandException) { |
| 1560 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1561 | CommandException.Error error = |
| 1562 | ((CommandException) (ar.exception)).getCommandError(); |
| 1563 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1564 | request.result = |
| 1565 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1566 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1567 | } else { |
| 1568 | loge("setAllowedCarriers: Unknown exception"); |
| 1569 | } |
| 1570 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1571 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1572 | break; |
| 1573 | |
| 1574 | case CMD_GET_ALLOWED_CARRIERS: |
| 1575 | request = (MainThreadRequest) msg.obj; |
| 1576 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1577 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1578 | break; |
| 1579 | |
| 1580 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1581 | ar = (AsyncResult) msg.obj; |
| 1582 | request = (MainThreadRequest) ar.userObj; |
| 1583 | if (ar.exception == null && ar.result != null) { |
| 1584 | request.result = ar.result; |
| 1585 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1586 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1587 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1588 | if (ar.result == null) { |
| 1589 | loge("getAllowedCarriers: Empty response"); |
| 1590 | } else if (ar.exception instanceof CommandException) { |
| 1591 | loge("getAllowedCarriers: CommandException: " + |
| 1592 | ar.exception); |
| 1593 | } else { |
| 1594 | loge("getAllowedCarriers: Unknown exception"); |
| 1595 | } |
| 1596 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1597 | if (request.argument != null) { |
| 1598 | // This is for the implementation of carrierRestrictionStatus. |
| 1599 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1600 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1601 | Set<Integer> callerCarrierIds = callbackInfo.getCarrierIds(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1602 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1603 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1604 | CarrierRestrictionRules carrierRestrictionRules = |
| 1605 | (CarrierRestrictionRules) ar.result; |
| 1606 | int carrierId = -1; |
| 1607 | try { |
| 1608 | CarrierIdentifier carrierIdentifier = |
| 1609 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1610 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1611 | carrierIdentifier); |
| 1612 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1613 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1614 | } |
| 1615 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 1616 | int restrictedStatus = |
| 1617 | TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED; |
| 1618 | if (carrierId != -1 && callerCarrierIds.contains(carrierId) && |
| 1619 | lockStatus == restrictedStatus) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1620 | lockStatus = TelephonyManager |
| 1621 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1622 | } |
| 1623 | } else { |
| 1624 | Rlog.e(LOG_TAG, |
| 1625 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1626 | } |
| 1627 | callback.accept(lockStatus); |
| 1628 | } else { |
| 1629 | // This is for the implementation of getAllowedCarriers. |
| 1630 | notifyRequester(request); |
| 1631 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1632 | break; |
| 1633 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1634 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1635 | ar = (AsyncResult) msg.obj; |
| 1636 | request = (MainThreadRequest) ar.userObj; |
| 1637 | if (ar.exception == null && ar.result != null) { |
| 1638 | request.result = ar.result; |
| 1639 | } else { |
| 1640 | request.result = new IllegalArgumentException( |
| 1641 | "Failed to retrieve Forbidden Plmns"); |
| 1642 | if (ar.result == null) { |
| 1643 | loge("getForbiddenPlmns: Empty response"); |
| 1644 | } else { |
| 1645 | loge("getForbiddenPlmns: Unknown exception"); |
| 1646 | } |
| 1647 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1648 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1649 | break; |
| 1650 | |
| 1651 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1652 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1653 | uiccPort = getUiccPortFromRequest(request); |
| 1654 | if (uiccPort == null) { |
| 1655 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1656 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1657 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1658 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1659 | break; |
| 1660 | } |
| 1661 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1662 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1663 | if (uiccApp == null) { |
| 1664 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1665 | + appType); |
| 1666 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1667 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1668 | break; |
| 1669 | } else { |
| 1670 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1671 | + " specified type -- " + appType); |
| 1672 | } |
| 1673 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1674 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1675 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1676 | break; |
| 1677 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1678 | case CMD_SWITCH_SLOTS: |
| 1679 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1680 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1681 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1682 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1683 | break; |
| 1684 | |
| 1685 | case EVENT_SWITCH_SLOTS_DONE: |
| 1686 | ar = (AsyncResult) msg.obj; |
| 1687 | request = (MainThreadRequest) ar.userObj; |
| 1688 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1689 | notifyRequester(request); |
| 1690 | break; |
| 1691 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1692 | request = (MainThreadRequest) msg.obj; |
| 1693 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1694 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1695 | break; |
| 1696 | |
| 1697 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1698 | ar = (AsyncResult) msg.obj; |
| 1699 | request = (MainThreadRequest) ar.userObj; |
| 1700 | if (ar.exception != null) { |
| 1701 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1702 | } else { |
| 1703 | int mode = ((int[]) ar.result)[0]; |
| 1704 | if (mode == 0) { |
| 1705 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1706 | } else { |
| 1707 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1708 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1709 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1710 | notifyRequester(request); |
| 1711 | break; |
| 1712 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1713 | request = (MainThreadRequest) msg.obj; |
| 1714 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1715 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1716 | break; |
| 1717 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1718 | ar = (AsyncResult) msg.obj; |
| 1719 | request = (MainThreadRequest) ar.userObj; |
| 1720 | if (ar.exception != null) { |
| 1721 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1722 | } else { |
| 1723 | request.result = ((int[]) ar.result)[0]; |
| 1724 | } |
| 1725 | notifyRequester(request); |
| 1726 | break; |
| 1727 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1728 | request = (MainThreadRequest) msg.obj; |
| 1729 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1730 | int mode = (int) request.argument; |
| 1731 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1732 | break; |
| 1733 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1734 | ar = (AsyncResult) msg.obj; |
| 1735 | request = (MainThreadRequest) ar.userObj; |
| 1736 | request.result = ar.exception == null; |
| 1737 | notifyRequester(request); |
| 1738 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1739 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1740 | request = (MainThreadRequest) msg.obj; |
| 1741 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1742 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1743 | break; |
| 1744 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1745 | ar = (AsyncResult) msg.obj; |
| 1746 | request = (MainThreadRequest) ar.userObj; |
| 1747 | if (ar.exception != null) { |
| 1748 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1749 | } else { |
| 1750 | request.result = ((int[]) ar.result)[0]; |
| 1751 | } |
| 1752 | notifyRequester(request); |
| 1753 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1754 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1755 | request = (MainThreadRequest) msg.obj; |
| 1756 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1757 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1758 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1759 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1760 | break; |
| 1761 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1762 | ar = (AsyncResult) msg.obj; |
| 1763 | request = (MainThreadRequest) ar.userObj; |
| 1764 | request.result = ar.exception == null; |
| 1765 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1766 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1767 | case CMD_GET_ALL_CELL_INFO: |
| 1768 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1769 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1770 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1771 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1772 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1773 | ar = (AsyncResult) msg.obj; |
| 1774 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1775 | // If a timeout occurs, the response will be null |
| 1776 | request.result = (ar.exception == null && ar.result != null) |
| 1777 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1778 | synchronized (request) { |
| 1779 | request.notifyAll(); |
| 1780 | } |
| 1781 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1782 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1783 | request = (MainThreadRequest) msg.obj; |
| 1784 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1785 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1786 | break; |
| 1787 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1788 | ar = (AsyncResult) msg.obj; |
| 1789 | request = (MainThreadRequest) ar.userObj; |
| 1790 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1791 | try { |
| 1792 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1793 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1794 | cb.onError( |
| 1795 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1796 | ar.exception.getClass().getName(), |
| 1797 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1798 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1799 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1800 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1801 | } else { |
| 1802 | // use the result as returned |
| 1803 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1804 | } |
| 1805 | } catch (RemoteException re) { |
| 1806 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1807 | } |
| 1808 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1809 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1810 | request = (MainThreadRequest) msg.obj; |
| 1811 | WorkSource ws = (WorkSource) request.argument; |
| 1812 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1813 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1814 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1815 | } |
| 1816 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1817 | ar = (AsyncResult) msg.obj; |
| 1818 | request = (MainThreadRequest) ar.userObj; |
| 1819 | if (ar.exception == null) { |
| 1820 | request.result = ar.result; |
| 1821 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1822 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1823 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1824 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | synchronized (request) { |
| 1828 | request.notifyAll(); |
| 1829 | } |
| 1830 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1831 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1832 | case CMD_MODEM_REBOOT: |
| 1833 | request = (MainThreadRequest) msg.obj; |
| 1834 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1835 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1836 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1837 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1838 | handleNullReturnEvent(msg, "rebootModem"); |
| 1839 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1840 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1841 | request = (MainThreadRequest) msg.obj; |
| 1842 | boolean enable = (boolean) request.argument; |
| 1843 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1844 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1845 | PhoneConfigurationManager.getInstance() |
| 1846 | .enablePhone(request.phone, enable, onCompleted); |
| 1847 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1848 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1849 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1850 | ar = (AsyncResult) msg.obj; |
| 1851 | request = (MainThreadRequest) ar.userObj; |
| 1852 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1853 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1854 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1855 | if ((boolean) request.result) { |
| 1856 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1857 | updateModemStateMetrics(); |
| 1858 | } else { |
| 1859 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1860 | + ar.exception); |
| 1861 | } |
| 1862 | notifyRequester(request); |
| 1863 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1864 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1865 | case CMD_GET_MODEM_STATUS: |
| 1866 | request = (MainThreadRequest) msg.obj; |
| 1867 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1868 | PhoneConfigurationManager.getInstance() |
| 1869 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1870 | break; |
| 1871 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1872 | ar = (AsyncResult) msg.obj; |
| 1873 | request = (MainThreadRequest) ar.userObj; |
| 1874 | int id = request.phone.getPhoneId(); |
| 1875 | if (ar.exception == null && ar.result != null) { |
| 1876 | request.result = ar.result; |
| 1877 | //update the cache as modem status has changed |
| 1878 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1879 | (boolean) request.result); |
| 1880 | } else { |
| 1881 | // Return true if modem status cannot be retrieved. For most cases, |
| 1882 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1883 | // and disable modem are not supported. Modem is always on. |
| 1884 | // TODO: this should be fixed in R to support a third |
| 1885 | // status UNKNOWN b/131631629 |
| 1886 | request.result = true; |
| 1887 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1888 | + ar.exception); |
| 1889 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1890 | notifyRequester(request); |
| 1891 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1892 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1893 | request = (MainThreadRequest) msg.obj; |
| 1894 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1895 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1896 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1897 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1898 | break; |
| 1899 | } |
| 1900 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1901 | ar = (AsyncResult) msg.obj; |
| 1902 | request = (MainThreadRequest) ar.userObj; |
| 1903 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1904 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1905 | args.second.accept(ar.exception == null); |
| 1906 | notifyRequester(request); |
| 1907 | break; |
| 1908 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1909 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1910 | request = (MainThreadRequest) msg.obj; |
| 1911 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1912 | Phone phone = getPhoneFromRequest(request); |
| 1913 | if (phone != null) { |
| 1914 | phone.getSystemSelectionChannels(onCompleted); |
| 1915 | } else { |
| 1916 | loge("getSystemSelectionChannels: No phone object"); |
| 1917 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1918 | notifyRequester(request); |
| 1919 | } |
| 1920 | break; |
| 1921 | } |
| 1922 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1923 | ar = (AsyncResult) msg.obj; |
| 1924 | request = (MainThreadRequest) ar.userObj; |
| 1925 | if (ar.exception == null && ar.result != null) { |
| 1926 | request.result = ar.result; |
| 1927 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1928 | request.result = new IllegalStateException( |
| 1929 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1930 | if (ar.result == null) { |
| 1931 | loge("getSystemSelectionChannels: Empty response"); |
| 1932 | } else { |
| 1933 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1934 | } |
| 1935 | } |
| 1936 | notifyRequester(request); |
| 1937 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1938 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1939 | ar = (AsyncResult) msg.obj; |
| 1940 | request = (MainThreadRequest) ar.userObj; |
| 1941 | if (ar.exception == null && ar.result != null) { |
| 1942 | request.result = ar.result; |
| 1943 | } else { |
| 1944 | request.result = -1; |
| 1945 | loge("Failed to set Forbidden Plmns"); |
| 1946 | if (ar.result == null) { |
| 1947 | loge("setForbidenPlmns: Empty response"); |
| 1948 | } else if (ar.exception != null) { |
| 1949 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1950 | request.result = -1; |
| 1951 | } else { |
| 1952 | loge("setForbiddenPlmns: Unknown exception"); |
| 1953 | } |
| 1954 | } |
| 1955 | notifyRequester(request); |
| 1956 | break; |
| 1957 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1958 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1959 | uiccPort = getUiccPortFromRequest(request); |
| 1960 | if (uiccPort == null) { |
| 1961 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1962 | request.result = -1; |
| 1963 | notifyRequester(request); |
| 1964 | break; |
| 1965 | } |
| 1966 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1967 | (Pair<Integer, List<String>>) request.argument; |
| 1968 | appType = setFplmnsArgs.first; |
| 1969 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1970 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1971 | if (uiccApp == null) { |
| 1972 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1973 | request.result = -1; |
| 1974 | loge("Failed to get UICC App"); |
| 1975 | notifyRequester(request); |
| 1976 | } else { |
| 1977 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1978 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1979 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1980 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1981 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1982 | case CMD_ERASE_MODEM_CONFIG: |
| 1983 | request = (MainThreadRequest) msg.obj; |
| 1984 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1985 | defaultPhone.eraseModemConfig(onCompleted); |
| 1986 | break; |
| 1987 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1988 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1989 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1990 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1991 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1992 | request = (MainThreadRequest) msg.obj; |
| 1993 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1994 | notifyRequester(request); |
| 1995 | break; |
| 1996 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1997 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1998 | request = (MainThreadRequest) msg.obj; |
| 1999 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 2000 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 2001 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 2002 | changed.first, changed.second, onCompleted); |
| 2003 | break; |
| 2004 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 2005 | ar = (AsyncResult) msg.obj; |
| 2006 | request = (MainThreadRequest) ar.userObj; |
| 2007 | if (ar.exception == null) { |
| 2008 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2009 | // If the operation is successful, update the PIN storage |
| 2010 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 2011 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2012 | UiccController.getInstance().getPinStorage() |
| 2013 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2014 | } else { |
| 2015 | request.result = msg.arg1; |
| 2016 | } |
| 2017 | notifyRequester(request); |
| 2018 | break; |
| 2019 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2020 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2021 | request = (MainThreadRequest) msg.obj; |
| 2022 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2023 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2024 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2025 | enabled.first, enabled.second, onCompleted); |
| 2026 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2027 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2028 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2029 | ar = (AsyncResult) msg.obj; |
| 2030 | request = (MainThreadRequest) ar.userObj; |
| 2031 | if (ar.exception == null) { |
| 2032 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2033 | // If the operation is successful, update the PIN storage |
| 2034 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2035 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2036 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2037 | UiccController.getInstance().getPinStorage() |
| 2038 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2039 | } else { |
| 2040 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2041 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2042 | } else { |
| 2043 | request.result = msg.arg1; |
| 2044 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2045 | |
| 2046 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2047 | notifyRequester(request); |
| 2048 | break; |
| 2049 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2050 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2051 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2052 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2053 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2054 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2055 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2056 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2057 | |
| 2058 | case CMD_SET_DATA_THROTTLING: { |
| 2059 | request = (MainThreadRequest) msg.obj; |
| 2060 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2061 | DataThrottlingRequest dataThrottlingRequest = |
| 2062 | (DataThrottlingRequest) request.argument; |
| 2063 | Phone phone = getPhoneFromRequest(request); |
| 2064 | if (phone != null) { |
| 2065 | phone.setDataThrottling(onCompleted, |
| 2066 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2067 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2068 | } else { |
| 2069 | loge("setDataThrottling: No phone object"); |
| 2070 | request.result = |
| 2071 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2072 | notifyRequester(request); |
| 2073 | } |
| 2074 | |
| 2075 | break; |
| 2076 | } |
| 2077 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2078 | ar = (AsyncResult) msg.obj; |
| 2079 | request = (MainThreadRequest) ar.userObj; |
| 2080 | |
| 2081 | if (ar.exception == null) { |
| 2082 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2083 | } else if (ar.exception instanceof CommandException) { |
| 2084 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2085 | CommandException.Error error = |
| 2086 | ((CommandException) (ar.exception)).getCommandError(); |
| 2087 | |
| 2088 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2089 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2090 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2091 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2092 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2093 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2094 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2095 | } else { |
| 2096 | request.result = |
| 2097 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2098 | } |
| 2099 | } else { |
| 2100 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2101 | } |
| 2102 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2103 | notifyRequester(request); |
| 2104 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2105 | |
| 2106 | case CMD_SET_SIM_POWER: { |
| 2107 | request = (MainThreadRequest) msg.obj; |
| 2108 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2109 | request = (MainThreadRequest) msg.obj; |
| 2110 | int stateToSet = |
| 2111 | ((Pair<Integer, IIntegerConsumer>) |
| 2112 | request.argument).first; |
| 2113 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2114 | break; |
| 2115 | } |
| 2116 | case EVENT_SET_SIM_POWER_DONE: { |
| 2117 | ar = (AsyncResult) msg.obj; |
| 2118 | request = (MainThreadRequest) ar.userObj; |
| 2119 | IIntegerConsumer callback = |
| 2120 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2121 | if (ar.exception != null) { |
| 2122 | loge("setSimPower exception: " + ar.exception); |
| 2123 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2124 | .RESULT_ERROR_UNKNOWN; |
| 2125 | if (ar.exception instanceof CommandException) { |
| 2126 | CommandException.Error error = |
| 2127 | ((CommandException) (ar.exception)).getCommandError(); |
| 2128 | if (error == CommandException.Error.SIM_ERR) { |
| 2129 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2130 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2131 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2132 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2133 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2134 | } else { |
| 2135 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2136 | } |
| 2137 | } |
| 2138 | try { |
| 2139 | callback.accept(errorCode); |
| 2140 | } catch (RemoteException e) { |
| 2141 | // Ignore if the remote process is no longer available to call back. |
| 2142 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2143 | } |
| 2144 | } else { |
| 2145 | try { |
| 2146 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2147 | } catch (RemoteException e) { |
| 2148 | // Ignore if the remote process is no longer available to call back. |
| 2149 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2150 | } |
| 2151 | } |
| 2152 | break; |
| 2153 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2154 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2155 | request = (MainThreadRequest) msg.obj; |
| 2156 | |
| 2157 | final Phone phone = getPhoneFromRequest(request); |
| 2158 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2159 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2160 | notifyRequester(request); |
| 2161 | break; |
| 2162 | } |
| 2163 | |
| 2164 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2165 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2166 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2167 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2168 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2169 | request.subId, pair.first /*callingUid*/, |
| 2170 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2171 | break; |
| 2172 | } |
| 2173 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2174 | ar = (AsyncResult) msg.obj; |
| 2175 | request = (MainThreadRequest) ar.userObj; |
| 2176 | // request.result will be the exception of ar if present, true otherwise. |
| 2177 | // Be cautious not to leave result null which will wait() forever |
| 2178 | request.result = ar.exception != null ? ar.exception : true; |
| 2179 | notifyRequester(request); |
| 2180 | break; |
| 2181 | } |
| 2182 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2183 | request = (MainThreadRequest) msg.obj; |
| 2184 | |
| 2185 | Phone phone = getPhoneFromRequest(request); |
| 2186 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2187 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2188 | notifyRequester(request); |
| 2189 | break; |
| 2190 | } |
| 2191 | |
| 2192 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2193 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2194 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2195 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2196 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2197 | request.subId, pair.first /*callingUid*/, |
| 2198 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2199 | break; |
| 2200 | } |
| 2201 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2202 | ar = (AsyncResult) msg.obj; |
| 2203 | request = (MainThreadRequest) ar.userObj; |
| 2204 | request.result = ar.exception != null ? ar.exception : true; |
| 2205 | notifyRequester(request); |
| 2206 | break; |
| 2207 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2208 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2209 | case CMD_GET_SLICING_CONFIG: { |
| 2210 | request = (MainThreadRequest) msg.obj; |
| 2211 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2212 | request.phone.getSlicingConfig(onCompleted); |
| 2213 | break; |
| 2214 | } |
| 2215 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2216 | ar = (AsyncResult) msg.obj; |
| 2217 | request = (MainThreadRequest) ar.userObj; |
| 2218 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2219 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2220 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2221 | Bundle bundle = new Bundle(); |
| 2222 | int resultCode = 0; |
| 2223 | if (ar.exception != null) { |
| 2224 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2225 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2226 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2227 | } else if (ar.result == null) { |
| 2228 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2229 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2230 | } else { |
| 2231 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2232 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2233 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2237 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2238 | } |
| 2239 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2240 | result.send(resultCode, bundle); |
| 2241 | notifyRequester(request); |
| 2242 | break; |
| 2243 | } |
| 2244 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2246 | request = (MainThreadRequest) msg.obj; |
| 2247 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2248 | PurchasePremiumCapabilityArgument arg = |
| 2249 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2250 | SlicePurchaseController.getInstance(request.phone, mFeatureFlags) |
| 2251 | .purchasePremiumCapability(arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2252 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2253 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2254 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2255 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2256 | ar = (AsyncResult) msg.obj; |
| 2257 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2258 | PurchasePremiumCapabilityArgument arg = |
| 2259 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2260 | try { |
| 2261 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2262 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2263 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2264 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 2265 | + ", result=" |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2266 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2267 | } catch (RemoteException e) { |
| 2268 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2269 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2270 | + " failed: " + e; |
| 2271 | if (DBG) log(logStr); |
| 2272 | AnomalyReporter.reportAnomaly( |
| 2273 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2274 | } |
| 2275 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2276 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2277 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2278 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2279 | request = (MainThreadRequest) msg.obj; |
| 2280 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2281 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2282 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2283 | notifyRequester(request); |
| 2284 | break; |
| 2285 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | default: |
| 2287 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2288 | break; |
| 2289 | } |
| 2290 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2291 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2292 | private void notifyRequester(MainThreadRequest request) { |
| 2293 | synchronized (request) { |
| 2294 | request.notifyAll(); |
| 2295 | } |
| 2296 | } |
| 2297 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2298 | private void handleNullReturnEvent(Message msg, String command) { |
| 2299 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2300 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2301 | if (ar.exception == null) { |
| 2302 | request.result = true; |
| 2303 | } else { |
| 2304 | request.result = false; |
| 2305 | if (ar.exception instanceof CommandException) { |
| 2306 | loge(command + ": CommandException: " + ar.exception); |
| 2307 | } else { |
| 2308 | loge(command + ": Unknown exception"); |
| 2309 | } |
| 2310 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2311 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Posts the specified command to be executed on the main thread, |
| 2317 | * waits for the request to complete, and returns the result. |
| 2318 | * @see #sendRequestAsync |
| 2319 | */ |
| 2320 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2321 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2322 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * Posts the specified command to be executed on the main thread, |
| 2327 | * waits for the request to complete, and returns the result. |
| 2328 | * @see #sendRequestAsync |
| 2329 | */ |
| 2330 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2331 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2332 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * Posts the specified command to be executed on the main thread, |
| 2337 | * waits for the request to complete, and returns the result. |
| 2338 | * @see #sendRequestAsync |
| 2339 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2340 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2341 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2342 | } |
| 2343 | |
| 2344 | /** |
| 2345 | * Posts the specified command to be executed on the main thread, |
| 2346 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2347 | * if not timeout or null otherwise. |
| 2348 | * @see #sendRequestAsync |
| 2349 | */ |
| 2350 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2351 | long timeoutInMs) { |
| 2352 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | /** |
| 2356 | * Posts the specified command to be executed on the main thread, |
| 2357 | * waits for the request to complete, and returns the result. |
| 2358 | * @see #sendRequestAsync |
| 2359 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2360 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2361 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | /** |
| 2365 | * Posts the specified command to be executed on the main thread, |
| 2366 | * waits for the request to complete, and returns the result. |
| 2367 | * @see #sendRequestAsync |
| 2368 | */ |
| 2369 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2370 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2371 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2375 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2376 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2377 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2378 | * @see #sendRequestAsync |
| 2379 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2380 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2381 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2382 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2383 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2384 | } |
| 2385 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2386 | MainThreadRequest request = null; |
| 2387 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2388 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2389 | } else if (phone != null) { |
| 2390 | request = new MainThreadRequest(argument, phone, workSource); |
| 2391 | } else { |
| 2392 | request = new MainThreadRequest(argument, subId, workSource); |
| 2393 | } |
| 2394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2396 | msg.sendToTarget(); |
| 2397 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2398 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2400 | if (timeoutInMs >= 0) { |
| 2401 | // Wait for at least timeoutInMs before returning null request result |
| 2402 | long now = SystemClock.elapsedRealtime(); |
| 2403 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2404 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2405 | try { |
| 2406 | request.wait(deadline - now); |
| 2407 | } catch (InterruptedException e) { |
| 2408 | // Do nothing, go back and check if request is completed or timeout |
| 2409 | } finally { |
| 2410 | now = SystemClock.elapsedRealtime(); |
| 2411 | } |
| 2412 | } |
| 2413 | } else { |
| 2414 | // Wait for the request to complete |
| 2415 | while (request.result == null) { |
| 2416 | try { |
| 2417 | request.wait(); |
| 2418 | } catch (InterruptedException e) { |
| 2419 | // Do nothing, go back and wait until the request is complete |
| 2420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2424 | if (request.result == null) { |
| 2425 | Log.wtf(LOG_TAG, |
| 2426 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | return request.result; |
| 2429 | } |
| 2430 | |
| 2431 | /** |
| 2432 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2433 | * Posts the specified command to be executed on the main thread, and |
| 2434 | * returns immediately. |
| 2435 | * @see #sendRequest |
| 2436 | */ |
| 2437 | private void sendRequestAsync(int command) { |
| 2438 | mMainThreadHandler.sendEmptyMessage(command); |
| 2439 | } |
| 2440 | |
| 2441 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2442 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2443 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2444 | */ |
| 2445 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2446 | sendRequestAsync(command, argument, null, null); |
| 2447 | } |
| 2448 | |
| 2449 | /** |
| 2450 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2451 | * @see {@link #sendRequest(int,Object)} |
| 2452 | */ |
| 2453 | private void sendRequestAsync( |
| 2454 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2455 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2456 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2457 | msg.sendToTarget(); |
| 2458 | } |
| 2459 | |
| 2460 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2461 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2462 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2463 | */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2464 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | synchronized (PhoneInterfaceManager.class) { |
| 2466 | if (sInstance == null) { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2467 | sInstance = new PhoneInterfaceManager(app, featureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | } else { |
| 2469 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2470 | } |
| 2471 | return sInstance; |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | /** Private constructor; @see init() */ |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2476 | private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | mApp = app; |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 2478 | mFeatureFlags = featureFlags; |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 2479 | mTelecomFeatureFlags = new com.android.server.telecom.flags.FeatureFlagsImpl(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2481 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2482 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2483 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2485 | mMainThreadHandler = new MainThreadHandler(); |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2486 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2487 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2488 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2489 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2490 | mNotifyUserActivity = new AtomicBoolean(false); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2491 | mPackageManager = app.getPackageManager(); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 2492 | mSatelliteAccessController = SatelliteAccessController.getOrCreateInstance( |
| 2493 | getDefaultPhone().getContext(), featureFlags); |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 2494 | mVendorApiLevel = SystemProperties.getInt( |
| 2495 | "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); |
| 2496 | |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2497 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2499 | CarrierAllowListInfo.loadInstance(mApp); |
Hyosun Kim | 240214a | 2023-11-02 13:30:15 +0000 | [diff] [blame] | 2500 | |
| 2501 | // Create the SatelliteEntitlementController singleton, for using the get the |
| 2502 | // entitlementStatus for satellite service. |
| 2503 | SatelliteEntitlementController.make(mApp, mFeatureFlags); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2506 | @VisibleForTesting |
| 2507 | public SharedPreferences getSharedPreferences() { |
| 2508 | return mTelephonySharedPreferences; |
| 2509 | } |
| 2510 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2511 | /** |
| 2512 | * Get the default phone for this device. |
| 2513 | */ |
| 2514 | @VisibleForTesting |
| 2515 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2516 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2517 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2518 | } |
| 2519 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | private void publish() { |
| 2521 | if (DBG) log("publish: " + this); |
| 2522 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2523 | TelephonyFrameworkInitializer |
| 2524 | .getTelephonyServiceManager() |
| 2525 | .getTelephonyServiceRegisterer() |
| 2526 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2529 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2530 | if (request.phone != null) { |
| 2531 | return request.phone; |
| 2532 | } else { |
| 2533 | return getPhoneFromSubId(request.subId); |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | private Phone getPhoneFromSubId(int subId) { |
| 2538 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2539 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2540 | } |
| 2541 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2542 | /** |
| 2543 | * Get phone object associated with a subscription. |
| 2544 | * Return default phone if phone object associated with subscription is null |
| 2545 | * @param subId - subscriptionId |
| 2546 | * @return phone object associated with a subscription or default phone if null. |
| 2547 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2548 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2549 | Phone phone = getPhoneFromSubId(subId); |
| 2550 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2551 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2552 | phone = getDefaultPhone(); |
| 2553 | } |
| 2554 | return phone; |
| 2555 | } |
| 2556 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2557 | @Nullable |
| 2558 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2559 | Phone phone = getPhoneFromRequest(request); |
| 2560 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2561 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2562 | } |
| 2563 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2564 | /** |
| 2565 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2566 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2567 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2568 | * @return The Phone associated the sub Id |
| 2569 | */ |
| 2570 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2571 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2574 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2575 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2576 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2577 | } |
| 2578 | |
| 2579 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2580 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2581 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2584 | private boolean isImsAvailableOnDevice() { |
| 2585 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2586 | if (pm == null) { |
| 2587 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2588 | // so do not throw error and allow. |
| 2589 | return true; |
| 2590 | } |
| 2591 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2592 | } |
| 2593 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | public void dial(String number) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2595 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2596 | PackageManager.FEATURE_TELEPHONY_CALLING, "dial"); |
| 2597 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2598 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2601 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | if (DBG) log("dial: " + number); |
| 2603 | // No permission check needed here: This is just a wrapper around the |
| 2604 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2605 | // the UI before it does anything. |
| 2606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | String url = createTelUrl(number); |
| 2610 | if (url == null) { |
| 2611 | return; |
| 2612 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2615 | PhoneConstants.State state = mCM.getState(subId); |
| 2616 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2617 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2618 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2619 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | } |
| 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2627 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2630 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2631 | if (DBG) log("call: " + number); |
| 2632 | |
| 2633 | // This is just a wrapper around the ACTION_CALL intent, but we still |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2634 | // need to do a permission check since we're calling startActivityAsUser() |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2635 | // from the context of the phone app. |
| 2636 | enforceCallPermission(); |
| 2637 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2638 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | != AppOpsManager.MODE_ALLOWED) { |
| 2640 | return; |
| 2641 | } |
| 2642 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2643 | enforceTelephonyFeatureWithException(callingPackage, |
| 2644 | PackageManager.FEATURE_TELEPHONY_CALLING, "call"); |
| 2645 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | final long identity = Binder.clearCallingIdentity(); |
| 2647 | try { |
| 2648 | String url = createTelUrl(number); |
| 2649 | if (url == null) { |
| 2650 | return; |
| 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2653 | boolean isValid = false; |
| 2654 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2655 | if (slist != null) { |
| 2656 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2657 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2658 | isValid = true; |
| 2659 | break; |
| 2660 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2661 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2662 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | if (!isValid) { |
| 2664 | return; |
| 2665 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2666 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2668 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2669 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 2670 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | } finally { |
| 2672 | Binder.restoreCallingIdentity(identity); |
| 2673 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2676 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2677 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2678 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2679 | } |
| 2680 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2681 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2682 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2683 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2684 | } |
| 2685 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2686 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2689 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2690 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 2691 | "supplyPinReportResultForSubscriber"); |
| 2692 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | final long identity = Binder.clearCallingIdentity(); |
| 2694 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2695 | Phone phone = getPhone(subId); |
| 2696 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | checkSimPin.start(); |
| 2698 | return checkSimPin.unlockSim(null, pin); |
| 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
| 2701 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2704 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2706 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2707 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2708 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "supplyPukForSubscriber"); |
| 2709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2712 | Phone phone = getPhone(subId); |
| 2713 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2714 | checkSimPuk.start(); |
| 2715 | return checkSimPuk.unlockSim(puk, pin); |
| 2716 | } finally { |
| 2717 | Binder.restoreCallingIdentity(identity); |
| 2718 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2722 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | * a synchronous one. |
| 2724 | */ |
| 2725 | private static class UnlockSim extends Thread { |
| 2726 | |
| 2727 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2728 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | |
| 2730 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2731 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2732 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2733 | |
| 2734 | // For replies from SimCard interface |
| 2735 | private Handler mHandler; |
| 2736 | |
| 2737 | // For async handler to identify request type |
| 2738 | private static final int SUPPLY_PIN_COMPLETE = 100; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2739 | private static final int SUPPLY_PIN_DELAYED = 101; |
| 2740 | private static final int SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS = 10000; |
| 2741 | private static final UUID SUPPLY_PIN_UUID = UUID.fromString( |
| 2742 | "d3768135-4323-491d-a6c8-bda01fc89040"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2743 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2744 | UnlockSim(int phoneId, IccCard simCard) { |
| 2745 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | mSimCard = simCard; |
| 2747 | } |
| 2748 | |
| 2749 | @Override |
| 2750 | public void run() { |
| 2751 | Looper.prepare(); |
| 2752 | synchronized (UnlockSim.this) { |
| 2753 | mHandler = new Handler() { |
| 2754 | @Override |
| 2755 | public void handleMessage(Message msg) { |
| 2756 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2757 | switch (msg.what) { |
| 2758 | case SUPPLY_PIN_COMPLETE: |
| 2759 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2760 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2761 | mRetryCount = msg.arg1; |
| 2762 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2763 | CommandException.Error error = null; |
| 2764 | if (ar.exception instanceof CommandException) { |
| 2765 | error = ((CommandException) (ar.exception)) |
| 2766 | .getCommandError(); |
| 2767 | } |
| 2768 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2769 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2770 | } else if (error == CommandException.Error.ABORTED) { |
| 2771 | /* When UiccCardApp dispose, handle message and return |
| 2772 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2773 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2774 | } else { |
| 2775 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2776 | } |
| 2777 | } else { |
| 2778 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | mDone = true; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2781 | removeMessages(SUPPLY_PIN_DELAYED); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2782 | UnlockSim.this.notifyAll(); |
| 2783 | } |
| 2784 | break; |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2785 | case SUPPLY_PIN_DELAYED: |
| 2786 | if(!mDone) { |
| 2787 | String logStr = "Delay in receiving SIM PIN response "; |
| 2788 | if (DBG) log(logStr); |
| 2789 | AnomalyReporter.reportAnomaly(SUPPLY_PIN_UUID, logStr); |
| 2790 | } |
| 2791 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | }; |
| 2795 | UnlockSim.this.notifyAll(); |
| 2796 | } |
| 2797 | Looper.loop(); |
| 2798 | } |
| 2799 | |
| 2800 | /* |
| 2801 | * Use PIN or PUK to unlock SIM card |
| 2802 | * |
| 2803 | * If PUK is null, unlock SIM card with PIN |
| 2804 | * |
| 2805 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2806 | * |
| 2807 | * Besides, since it is reused in class level, the thread's looper will be stopped to avoid |
| 2808 | * its thread leak. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2810 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | |
| 2812 | while (mHandler == null) { |
| 2813 | try { |
| 2814 | wait(); |
| 2815 | } catch (InterruptedException e) { |
| 2816 | Thread.currentThread().interrupt(); |
| 2817 | } |
| 2818 | } |
| 2819 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2820 | |
| 2821 | if (puk == null) { |
| 2822 | mSimCard.supplyPin(pin, callback); |
| 2823 | } else { |
| 2824 | mSimCard.supplyPuk(puk, pin, callback); |
| 2825 | } |
| 2826 | |
| 2827 | while (!mDone) { |
| 2828 | try { |
| 2829 | Log.d(LOG_TAG, "wait for done"); |
arunvoddu | 7bf930c | 2024-05-20 04:24:40 +0000 | [diff] [blame] | 2830 | mHandler.sendEmptyMessageDelayed(SUPPLY_PIN_DELAYED, |
| 2831 | SUPPLY_PIN_DELAYED_TIMER_IN_MILLIS); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2832 | wait(); |
| 2833 | } catch (InterruptedException e) { |
| 2834 | // Restore the interrupted status |
| 2835 | Thread.currentThread().interrupt(); |
| 2836 | } |
| 2837 | } |
| 2838 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2839 | int[] resultArray = new int[2]; |
| 2840 | resultArray[0] = mResult; |
| 2841 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2842 | |
| 2843 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2844 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2845 | } |
Mengjun Leng | 7ddbbfc | 2023-08-17 11:53:32 +0530 | [diff] [blame] | 2846 | // This instance is no longer reused, so quit its thread's looper. |
| 2847 | mHandler.getLooper().quitSafely(); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2848 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2849 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | } |
| 2851 | } |
| 2852 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2853 | /** |
| 2854 | * This method has been removed due to privacy and stability concerns. |
| 2855 | */ |
| 2856 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2858 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2859 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2862 | @Override |
| 2863 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2864 | mApp.getSystemService(AppOpsManager.class) |
| 2865 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2866 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2867 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2868 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2869 | // Callers targeting S have no business invoking this method. |
| 2870 | return; |
| 2871 | } |
| 2872 | |
| 2873 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2874 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2875 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2876 | .setCallingPackage(callingPackage) |
| 2877 | .setCallingFeatureId(null) |
| 2878 | .setCallingPid(Binder.getCallingPid()) |
| 2879 | .setCallingUid(Binder.getCallingUid()) |
| 2880 | .setMethod("updateServiceLocation") |
| 2881 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2882 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2883 | .build()); |
| 2884 | // Apps that lack location permission have no business calling this method; |
| 2885 | // however, because no permission was declared in the public API, denials must |
| 2886 | // all be "soft". |
| 2887 | switch (locationResult) { |
| 2888 | case DENIED_HARD: /* fall through */ |
| 2889 | case DENIED_SOFT: |
| 2890 | return; |
| 2891 | } |
| 2892 | |
| 2893 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2896 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2897 | } finally { |
| 2898 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2899 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2902 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2903 | @Override |
| 2904 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2905 | return isRadioOnWithFeature(callingPackage, null); |
| 2906 | } |
| 2907 | |
| 2908 | |
| 2909 | @Override |
| 2910 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2911 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2912 | callingFeatureId); |
| 2913 | } |
| 2914 | |
| 2915 | @Deprecated |
| 2916 | @Override |
| 2917 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2918 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2921 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2922 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2923 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2925 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2926 | return false; |
| 2927 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2929 | enforceTelephonyFeatureWithException(callingPackage, |
| 2930 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isRadioOnWithFeature"); |
| 2931 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | return isRadioOnForSubscriber(subId); |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
| 2937 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2941 | final long identity = Binder.clearCallingIdentity(); |
| 2942 | try { |
| 2943 | final Phone phone = getPhone(subId); |
| 2944 | if (phone != null) { |
| 2945 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2946 | } else { |
| 2947 | return false; |
| 2948 | } |
| 2949 | } finally { |
| 2950 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2951 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2955 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2956 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2957 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2958 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2959 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2960 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2961 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 2962 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "toggleRadioOnOffForSubscriber"); |
| 2963 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2964 | final long identity = Binder.clearCallingIdentity(); |
| 2965 | try { |
| 2966 | final Phone phone = getPhone(subId); |
| 2967 | if (phone != null) { |
| 2968 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2969 | } |
| 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2972 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2976 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2979 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2980 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | |
| 2982 | final long identity = Binder.clearCallingIdentity(); |
| 2983 | try { |
| 2984 | final Phone phone = getPhone(subId); |
| 2985 | if (phone == null) { |
| 2986 | return false; |
| 2987 | } |
| 2988 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2989 | toggleRadioOnOffForSubscriber(subId); |
| 2990 | } |
| 2991 | return true; |
| 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2994 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2995 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2996 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2997 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2998 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 2999 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 3000 | if (!mApp.getResources().getBoolean( |
| 3001 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3002 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3003 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needMobileRadioShutdown"); |
| 3004 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3005 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3006 | /* |
| 3007 | * If any of the Radios are available, it will need to be |
| 3008 | * shutdown. So return true if any Radio is available. |
| 3009 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3013 | Phone phone = PhoneFactory.getPhone(i); |
| 3014 | if (phone != null && phone.isRadioAvailable()) return true; |
| 3015 | } |
| 3016 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 3017 | return false; |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3020 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3024 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3025 | enforceModifyPermission(); |
| 3026 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3027 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3028 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "shutdownMobileRadios"); |
| 3029 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
| 3032 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3033 | logv("Shutting down Phone " + i); |
| 3034 | shutdownRadioUsingPhoneId(i); |
| 3035 | } |
| 3036 | } finally { |
| 3037 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3042 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3043 | if (phone != null && phone.isRadioAvailable()) { |
| 3044 | phone.shutdownRadio(); |
| 3045 | } |
| 3046 | } |
| 3047 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3048 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 3049 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3051 | if (!turnOn) { |
| 3052 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 3053 | } |
| 3054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | final long identity = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 3058 | if (defaultPhone != null) { |
| 3059 | defaultPhone.setRadioPower(turnOn); |
| 3060 | return true; |
| 3061 | } else { |
| 3062 | loge("There's no default phone."); |
| 3063 | return false; |
| 3064 | } |
| 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 3067 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3070 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3071 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3073 | if (!turnOn) { |
| 3074 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3075 | + ",callingPackage=" + getCurrentPackageName()); |
| 3076 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3077 | final long identity = Binder.clearCallingIdentity(); |
| 3078 | try { |
| 3079 | final Phone phone = getPhone(subId); |
| 3080 | if (phone != null) { |
| 3081 | phone.setRadioPower(turnOn); |
| 3082 | return true; |
| 3083 | } else { |
| 3084 | return false; |
| 3085 | } |
| 3086 | } finally { |
| 3087 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3088 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3091 | /** |
| 3092 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3093 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3094 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3095 | * powering it off, and these radio off votes will be cleared. |
| 3096 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3097 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3098 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3099 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3100 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3101 | * check its vote. |
| 3102 | * |
| 3103 | * @param subId The subscription ID. |
| 3104 | * @param reason The reason for powering off radio. |
| 3105 | * @return true on success and false on failure. |
| 3106 | */ |
| 3107 | public boolean requestRadioPowerOffForReason(int subId, |
| 3108 | @TelephonyManager.RadioPowerReason int reason) { |
| 3109 | enforceModifyPermission(); |
| 3110 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3111 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3112 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestRadioPowerOffForReason"); |
| 3113 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3114 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3115 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3118 | boolean result = false; |
| 3119 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3120 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3121 | phone.setRadioPowerForReason(false, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3122 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3123 | if (!result) { |
| 3124 | loge("requestRadioPowerOffForReason: no phone exists"); |
| 3125 | } |
| 3126 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | /** |
| 3133 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3134 | * {@link requestRadioPowerOffForReason}. |
| 3135 | * |
| 3136 | * @param subId The subscription ID. |
| 3137 | * @param reason The reason for powering off radio. |
| 3138 | * @return true on success and false on failure. |
| 3139 | */ |
| 3140 | public boolean clearRadioPowerOffForReason(int subId, |
| 3141 | @TelephonyManager.RadioPowerReason int reason) { |
| 3142 | enforceModifyPermission(); |
| 3143 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3144 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3145 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearRadioPowerOffForReason"); |
| 3146 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3147 | final long identity = Binder.clearCallingIdentity(); |
| 3148 | try { |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3149 | boolean result = false; |
| 3150 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3151 | result = true; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3152 | phone.setRadioPowerForReason(true, reason); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3153 | } |
Thomas Nguyen | 45d46d6 | 2023-09-28 21:11:06 -0700 | [diff] [blame] | 3154 | if (!result) { |
| 3155 | loge("clearRadioPowerOffForReason: no phone exists"); |
| 3156 | } |
| 3157 | return result; |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3158 | } finally { |
| 3159 | Binder.restoreCallingIdentity(identity); |
| 3160 | } |
| 3161 | } |
| 3162 | |
| 3163 | /** |
| 3164 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3165 | * |
| 3166 | * @param subId The subscription ID. |
| 3167 | * @param callingPackage The package making the call. |
| 3168 | * @param callingFeatureId The feature in the package. |
| 3169 | * @return List of reasons for powering off radio. |
| 3170 | */ |
| 3171 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3172 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3173 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3174 | enforceTelephonyFeatureWithException(callingPackage, |
| 3175 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerOffReasons"); |
| 3176 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3177 | final long identity = Binder.clearCallingIdentity(); |
| 3178 | List result = new ArrayList(); |
| 3179 | try { |
| 3180 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3181 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3182 | return result; |
| 3183 | } |
| 3184 | |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3185 | final Phone phone = getPhoneFromSubIdOrDefault(subId); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3186 | if (phone != null) { |
| 3187 | result.addAll(phone.getRadioPowerOffReasons()); |
Thomas Nguyen | b47fc3c | 2023-04-06 13:30:32 -0700 | [diff] [blame] | 3188 | } else { |
| 3189 | loge("getRadioPowerOffReasons: phone is null"); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3190 | } |
| 3191 | } finally { |
| 3192 | Binder.restoreCallingIdentity(identity); |
| 3193 | } |
| 3194 | return result; |
| 3195 | } |
| 3196 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3197 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3198 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3199 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3202 | enforceTelephonyFeatureWithException(callingPackage, |
| 3203 | PackageManager.FEATURE_TELEPHONY_DATA, "enableDataConnectivity"); |
| 3204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | final long identity = Binder.clearCallingIdentity(); |
| 3206 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3207 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3209 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3210 | phone.getDataSettingsManager().setDataEnabled( |
| 3211 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | return true; |
| 3213 | } else { |
| 3214 | return false; |
| 3215 | } |
| 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3218 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3221 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3222 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3223 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3224 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3225 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3226 | enforceTelephonyFeatureWithException(callingPackage, |
| 3227 | PackageManager.FEATURE_TELEPHONY_DATA, "disableDataConnectivity"); |
| 3228 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | final long identity = Binder.clearCallingIdentity(); |
| 3230 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3231 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3232 | final Phone phone = getPhone(subId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 3233 | if (phone != null && phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3234 | phone.getDataSettingsManager().setDataEnabled( |
| 3235 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3236 | return true; |
| 3237 | } else { |
| 3238 | return false; |
| 3239 | } |
| 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3242 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3245 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3246 | public boolean isDataConnectivityPossible(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3247 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3248 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataConnectivityPossible"); |
| 3249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | final long identity = Binder.clearCallingIdentity(); |
| 3251 | try { |
| 3252 | final Phone phone = getPhone(subId); |
| 3253 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3254 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | } else { |
| 3256 | return false; |
| 3257 | } |
| 3258 | } finally { |
| 3259 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3260 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3264 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3267 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3268 | enforceCallPermission(); |
| 3269 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3270 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3271 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "handleUssdRequest"); |
| 3272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3273 | final long identity = Binder.clearCallingIdentity(); |
| 3274 | try { |
| 3275 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3276 | return; |
| 3277 | } |
| 3278 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3279 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3280 | } finally { |
| 3281 | Binder.restoreCallingIdentity(identity); |
| 3282 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3283 | }; |
| 3284 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3285 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3286 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3287 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3288 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3289 | PackageManager.FEATURE_TELEPHONY_CALLING, "handlePinMmiForSubscriber"); |
| 3290 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3291 | final long identity = Binder.clearCallingIdentity(); |
| 3292 | try { |
| 3293 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3294 | return false; |
| 3295 | } |
| 3296 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3297 | } finally { |
| 3298 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3302 | /** |
| 3303 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3304 | * tag on getCallState Binder call. |
| 3305 | */ |
| 3306 | @Deprecated |
| 3307 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3308 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3309 | if (CompatChanges.isChangeEnabled( |
| 3310 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3311 | Binder.getCallingUid())) { |
| 3312 | // Do not allow this API to be called on API version 31+, it should only be |
| 3313 | // called on old apps using this Binder call directly. |
| 3314 | throw new SecurityException("This method can only be used for applications " |
| 3315 | + "targeting API version 30 or less."); |
| 3316 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3317 | final long identity = Binder.clearCallingIdentity(); |
| 3318 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3319 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3320 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | @Override |
| 3327 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3328 | if (CompatChanges.isChangeEnabled( |
| 3329 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3330 | Binder.getCallingUid())) { |
| 3331 | // Check READ_PHONE_STATE for API version 31+ |
| 3332 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3333 | featureId, "getCallStateForSubscription")) { |
| 3334 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3335 | + "targeting API level 31+."); |
| 3336 | } |
| 3337 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3338 | |
| 3339 | enforceTelephonyFeatureWithException(callingPackage, |
| 3340 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallStateForSubscription"); |
| 3341 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3342 | final long identity = Binder.clearCallingIdentity(); |
| 3343 | try { |
| 3344 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3345 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3346 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3347 | } finally { |
| 3348 | Binder.restoreCallingIdentity(identity); |
| 3349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3352 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3353 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3354 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | @Override |
| 3358 | public int getDataStateForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3359 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3360 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataStateForSubId"); |
| 3361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | final long identity = Binder.clearCallingIdentity(); |
| 3363 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3364 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3365 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3366 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | } else { |
| 3368 | return PhoneConstantConversions.convertDataState( |
| 3369 | PhoneConstants.DataState.DISCONNECTED); |
| 3370 | } |
| 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3373 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3374 | } |
| 3375 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3376 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3377 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3378 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3382 | public @DataActivityType int getDataActivityForSubId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3383 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3384 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivityForSubId"); |
| 3385 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | final long identity = Binder.clearCallingIdentity(); |
| 3387 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3388 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3389 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3390 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3391 | } else { |
| 3392 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3393 | } |
| 3394 | } finally { |
| 3395 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3396 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3400 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3401 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3402 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3403 | |
| 3404 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3405 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3406 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3407 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3408 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3409 | .setCallingPid(Binder.getCallingPid()) |
| 3410 | .setCallingUid(Binder.getCallingUid()) |
| 3411 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3412 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3413 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3414 | .build()); |
| 3415 | switch (locationResult) { |
| 3416 | case DENIED_HARD: |
| 3417 | throw new SecurityException("Not allowed to access cell location"); |
| 3418 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3419 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3420 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3423 | enforceTelephonyFeatureWithException(callingPackage, |
| 3424 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getCellLocation"); |
| 3425 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3426 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3427 | final long identity = Binder.clearCallingIdentity(); |
| 3428 | try { |
| 3429 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3430 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3431 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3432 | } finally { |
| 3433 | Binder.restoreCallingIdentity(identity); |
| 3434 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3437 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3438 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3439 | if (!mApp.getResources().getBoolean( |
| 3440 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3441 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3442 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkCountryIsoForPhone"); |
| 3443 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3444 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3445 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3446 | // registered cell info, so return a NULL country instead. |
| 3447 | final long identity = Binder.clearCallingIdentity(); |
| 3448 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3449 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3450 | // Get default phone in this case. |
| 3451 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3452 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3453 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3454 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3455 | if (phone == null) return ""; |
| 3456 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3457 | if (sst == null) return ""; |
| 3458 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3459 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3460 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3461 | } finally { |
| 3462 | Binder.restoreCallingIdentity(identity); |
| 3463 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3466 | /** |
| 3467 | * This method was removed due to potential issues caused by performing partial |
| 3468 | * updates of service state, and lack of a credible use case. |
| 3469 | * |
| 3470 | * This has the ability to break the telephony implementation by disabling notification of |
| 3471 | * changes in device connectivity. DO NOT USE THIS! |
| 3472 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3473 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3474 | public void enableLocationUpdates() { |
| 3475 | mApp.enforceCallingOrSelfPermission( |
| 3476 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3479 | /** |
| 3480 | * This method was removed due to potential issues caused by performing partial |
| 3481 | * updates of service state, and lack of a credible use case. |
| 3482 | * |
| 3483 | * This has the ability to break the telephony implementation by disabling notification of |
| 3484 | * changes in device connectivity. DO NOT USE THIS! |
| 3485 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3486 | @Override |
| 3487 | public void disableLocationUpdates() { |
| 3488 | mApp.enforceCallingOrSelfPermission( |
| 3489 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | @Override |
| 3493 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3494 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3495 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3496 | try { |
| 3497 | mApp.getSystemService(AppOpsManager.class) |
| 3498 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3499 | } catch (SecurityException e) { |
| 3500 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3501 | throw e; |
| 3502 | } |
| 3503 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3504 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3505 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3506 | throw new SecurityException( |
| 3507 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3508 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3509 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3510 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3511 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3512 | return null; |
| 3513 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3514 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3515 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3516 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNeighboringCellInfo"); |
| 3517 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3518 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3519 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3520 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3521 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3522 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3523 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3524 | for (CellInfo ci : info) { |
| 3525 | if (ci instanceof CellInfoGsm) { |
| 3526 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3527 | } else if (ci instanceof CellInfoWcdma) { |
| 3528 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3529 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3530 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3531 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3534 | private List<CellInfo> getCachedCellInfo() { |
| 3535 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3536 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3537 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3538 | if (info != null) cellInfos.addAll(info); |
| 3539 | } |
| 3540 | return cellInfos; |
| 3541 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3542 | |
| 3543 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3544 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3545 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3546 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3547 | |
| 3548 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3549 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3550 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3551 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3552 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3553 | .setCallingPid(Binder.getCallingPid()) |
| 3554 | .setCallingUid(Binder.getCallingUid()) |
| 3555 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3556 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3557 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3558 | .build()); |
| 3559 | switch (locationResult) { |
| 3560 | case DENIED_HARD: |
| 3561 | throw new SecurityException("Not allowed to access cell info"); |
| 3562 | case DENIED_SOFT: |
| 3563 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3566 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3567 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3568 | return getCachedCellInfo(); |
| 3569 | } |
| 3570 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3571 | enforceTelephonyFeatureWithException(callingPackage, |
| 3572 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllCellInfo"); |
| 3573 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3574 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3575 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3576 | final long identity = Binder.clearCallingIdentity(); |
| 3577 | try { |
| 3578 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3579 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3580 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3581 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3582 | if (info != null) cellInfos.addAll(info); |
| 3583 | } |
| 3584 | return cellInfos; |
| 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3590 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3591 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3592 | String callingFeatureId) { |
| 3593 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3594 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3598 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3599 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3600 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3601 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3604 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3605 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3606 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3607 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3608 | |
| 3609 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3610 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3611 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3612 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3613 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3614 | .setCallingPid(Binder.getCallingPid()) |
| 3615 | .setCallingUid(Binder.getCallingUid()) |
| 3616 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3617 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3618 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3619 | .build()); |
| 3620 | switch (locationResult) { |
| 3621 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3622 | if (TelephonyPermissions |
| 3623 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3624 | // Safetynet logging for b/154934934 |
| 3625 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3626 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3627 | throw new SecurityException("Not allowed to access cell info"); |
| 3628 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3629 | if (TelephonyPermissions |
| 3630 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3631 | // Safetynet logging for b/154934934 |
| 3632 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3633 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3634 | try { |
| 3635 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3636 | } catch (RemoteException re) { |
| 3637 | // Drop without consequences |
| 3638 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3639 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3642 | enforceTelephonyFeatureWithException(callingPackage, |
| 3643 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestCellInfoUpdateInternal"); |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3644 | |
| 3645 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3646 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3647 | |
| 3648 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3649 | } |
| 3650 | |
| 3651 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3652 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3653 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3654 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3655 | |
| 3656 | final long identity = Binder.clearCallingIdentity(); |
| 3657 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3658 | Phone phone = getPhone(subId); |
| 3659 | if (phone == null) { |
| 3660 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3661 | } else { |
| 3662 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3664 | } finally { |
| 3665 | Binder.restoreCallingIdentity(identity); |
| 3666 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3667 | } |
| 3668 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3669 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3670 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3671 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3672 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3673 | return null; |
| 3674 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3675 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3676 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3677 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3678 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3679 | return null; |
| 3680 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3681 | |
| 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | return phone.getImei(); |
| 3685 | } finally { |
| 3686 | Binder.restoreCallingIdentity(identity); |
| 3687 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3691 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3692 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3693 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3694 | callingFeatureId, "getPrimaryImei")) { |
| 3695 | throw new SecurityException("Caller does not have permission"); |
| 3696 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3697 | |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3701 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3702 | return phone.getImei(); |
| 3703 | } |
| 3704 | } |
| 3705 | throw new UnsupportedOperationException("Operation not supported"); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3712 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3713 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3714 | String tac = null; |
| 3715 | if (phone != null) { |
| 3716 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3717 | try { |
| 3718 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3719 | } catch (IndexOutOfBoundsException e) { |
| 3720 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3721 | return null; |
| 3722 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3723 | } |
| 3724 | return tac; |
| 3725 | } |
| 3726 | |
| 3727 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3728 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3729 | try { |
| 3730 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3731 | } catch (SecurityException se) { |
| 3732 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3733 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3734 | + Binder.getCallingUid()); |
| 3735 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3736 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3737 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3738 | return null; |
| 3739 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3740 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3741 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3742 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3743 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3744 | return null; |
| 3745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3747 | enforceTelephonyFeatureWithException(callingPackage, |
| 3748 | PackageManager.FEATURE_TELEPHONY_CDMA, "getMeidForSlot"); |
| 3749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | final long identity = Binder.clearCallingIdentity(); |
| 3751 | try { |
| 3752 | return phone.getMeid(); |
| 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(identity); |
| 3755 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3759 | public String getManufacturerCodeForSlot(int slotIndex) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3760 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3761 | PackageManager.FEATURE_TELEPHONY_CDMA, "getManufacturerCodeForSlot"); |
| 3762 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3763 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3764 | String manufacturerCode = null; |
| 3765 | if (phone != null) { |
| 3766 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3767 | try { |
| 3768 | manufacturerCode = |
| 3769 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3770 | } catch (IndexOutOfBoundsException e) { |
| 3771 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3772 | return null; |
| 3773 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3774 | } |
| 3775 | return manufacturerCode; |
| 3776 | } |
| 3777 | |
| 3778 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3779 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3780 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3781 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3782 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3783 | return null; |
| 3784 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3785 | int subId = phone.getSubId(); |
| 3786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3787 | mApp, subId, callingPackage, callingFeatureId, |
| 3788 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3789 | return null; |
| 3790 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3792 | enforceTelephonyFeatureWithException(callingPackage, |
| 3793 | PackageManager.FEATURE_TELEPHONY, "getDeviceSoftwareVersionForSlot"); |
| 3794 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3795 | final long identity = Binder.clearCallingIdentity(); |
| 3796 | try { |
| 3797 | return phone.getDeviceSvn(); |
| 3798 | } finally { |
| 3799 | Binder.restoreCallingIdentity(identity); |
| 3800 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3801 | } |
| 3802 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3803 | @Override |
| 3804 | public int getSubscriptionCarrierId(int subId) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 3805 | if (!mApp.getResources().getBoolean( |
| 3806 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 3807 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3808 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierId"); |
| 3809 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3810 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3811 | final long identity = Binder.clearCallingIdentity(); |
| 3812 | try { |
| 3813 | final Phone phone = getPhone(subId); |
| 3814 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3815 | } finally { |
| 3816 | Binder.restoreCallingIdentity(identity); |
| 3817 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | @Override |
| 3821 | public String getSubscriptionCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3822 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3823 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionCarrierName"); |
| 3824 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3825 | final long identity = Binder.clearCallingIdentity(); |
| 3826 | try { |
| 3827 | final Phone phone = getPhone(subId); |
| 3828 | return phone == null ? null : phone.getCarrierName(); |
| 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(identity); |
| 3831 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3832 | } |
| 3833 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3834 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3835 | public int getSubscriptionSpecificCarrierId(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3836 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3837 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSubscriptionSpecificCarrierId"); |
| 3838 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3839 | final long identity = Binder.clearCallingIdentity(); |
| 3840 | try { |
| 3841 | final Phone phone = getPhone(subId); |
| 3842 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3843 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(identity); |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3850 | public String getSubscriptionSpecificCarrierName(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3851 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3852 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 3853 | "getSubscriptionSpecificCarrierName"); |
| 3854 | |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3858 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3859 | } finally { |
| 3860 | Binder.restoreCallingIdentity(identity); |
| 3861 | } |
| 3862 | } |
| 3863 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3864 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3865 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3866 | if (!isSubscriptionMccMnc) { |
| 3867 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3868 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3869 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3870 | if (phone == null) { |
| 3871 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3872 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 3873 | |
| 3874 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 3875 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierIdFromMccMnc"); |
| 3876 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3877 | final long identity = Binder.clearCallingIdentity(); |
| 3878 | try { |
| 3879 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3880 | } finally { |
| 3881 | Binder.restoreCallingIdentity(identity); |
| 3882 | } |
| 3883 | } |
| 3884 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3885 | // |
| 3886 | // Internal helper methods. |
| 3887 | // |
| 3888 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3889 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3890 | * Make sure the caller is the calling package itself |
| 3891 | * |
| 3892 | * @throws SecurityException if the caller is not the calling package |
| 3893 | */ |
| 3894 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3895 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3896 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3897 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3898 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3899 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3900 | } catch (PackageManager.NameNotFoundException e) { |
| 3901 | // packageUid is -1 |
| 3902 | } |
| 3903 | if (packageUid != callingUid) { |
| 3904 | throw new SecurityException(message + ": Package " + callingPackage |
| 3905 | + " does not belong to " + callingUid); |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3910 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3911 | * |
| 3912 | * @throws SecurityException if the caller does not have the required permission |
| 3913 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3914 | @VisibleForTesting |
| 3915 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3916 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3917 | } |
| 3918 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3919 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3920 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3921 | * |
| 3922 | * @throws SecurityException if the caller does not have the required permission |
| 3923 | */ |
| 3924 | @VisibleForTesting |
| 3925 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3926 | enforceReadPermission(null); |
| 3927 | } |
| 3928 | |
| 3929 | /** |
| 3930 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3931 | * |
| 3932 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3933 | */ |
| 3934 | @VisibleForTesting |
| 3935 | public void enforceReadPermission(String msg) { |
| 3936 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3939 | private void enforceActiveEmergencySessionPermission() { |
| 3940 | mApp.enforceCallingOrSelfPermission( |
| 3941 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3942 | } |
| 3943 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3944 | /** |
| 3945 | * Make sure the caller has the CALL_PHONE permission. |
| 3946 | * |
| 3947 | * @throws SecurityException if the caller does not have the required permission |
| 3948 | */ |
| 3949 | private void enforceCallPermission() { |
| 3950 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3951 | } |
| 3952 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3953 | private void enforceSettingsPermission() { |
| 3954 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3955 | } |
| 3956 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3957 | private void enforceRebootPermission() { |
| 3958 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3959 | } |
| 3960 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3961 | /** |
| 3962 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3963 | * @param message - log message to print. |
| 3964 | * @throws SecurityException if the caller does not have the required permission |
| 3965 | */ |
| 3966 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3967 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3968 | } |
| 3969 | |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 3970 | /** |
| 3971 | * Make sure the caller has PACKAGE_USAGE_STATS permission. |
| 3972 | * @param message - log message to print. |
| 3973 | * @throws SecurityException if the caller does not have the required permission |
| 3974 | */ |
| 3975 | private void enforcePackageUsageStatsPermission(String message) { |
| 3976 | mApp.enforceCallingOrSelfPermission(permission.PACKAGE_USAGE_STATS, message); |
| 3977 | } |
| 3978 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3979 | private String createTelUrl(String number) { |
| 3980 | if (TextUtils.isEmpty(number)) { |
| 3981 | return null; |
| 3982 | } |
| 3983 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3984 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3987 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3988 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3989 | } |
| 3990 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3991 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3992 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3995 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3996 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3999 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4000 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4001 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4004 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4005 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 4006 | if (!mApp.getResources().getBoolean( |
| 4007 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 4008 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4009 | PackageManager.FEATURE_TELEPHONY, "getActivePhoneTypeForSlot"); |
| 4010 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4012 | final long identity = Binder.clearCallingIdentity(); |
| 4013 | try { |
| 4014 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4015 | if (phone == null) { |
| 4016 | return PhoneConstants.PHONE_TYPE_NONE; |
| 4017 | } else { |
| 4018 | return phone.getPhoneType(); |
| 4019 | } |
| 4020 | } finally { |
| 4021 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4022 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
| 4025 | /** |
| 4026 | * Returns the CDMA ERI icon index to display |
| 4027 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4028 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4029 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 4030 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 4031 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4035 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 4036 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4037 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4038 | mApp, subId, callingPackage, callingFeatureId, |
| 4039 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4040 | return -1; |
| 4041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4043 | enforceTelephonyFeatureWithException(callingPackage, |
| 4044 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 4045 | "getCdmaEriIconIndexForSubscriber"); |
| 4046 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4047 | final long identity = Binder.clearCallingIdentity(); |
| 4048 | try { |
| 4049 | final Phone phone = getPhone(subId); |
| 4050 | if (phone != null) { |
| 4051 | return phone.getCdmaEriIconIndex(); |
| 4052 | } else { |
| 4053 | return -1; |
| 4054 | } |
| 4055 | } finally { |
| 4056 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4057 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | /** |
| 4061 | * Returns the CDMA ERI icon mode, |
| 4062 | * 0 - ON |
| 4063 | * 1 - FLASHING |
| 4064 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4065 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4066 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 4067 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4068 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4071 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4072 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 4073 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4074 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4075 | mApp, subId, callingPackage, callingFeatureId, |
| 4076 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4077 | return -1; |
| 4078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4079 | |
| 4080 | final long identity = Binder.clearCallingIdentity(); |
| 4081 | try { |
| 4082 | final Phone phone = getPhone(subId); |
| 4083 | if (phone != null) { |
| 4084 | return phone.getCdmaEriIconMode(); |
| 4085 | } else { |
| 4086 | return -1; |
| 4087 | } |
| 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4090 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | /** |
| 4094 | * Returns the CDMA ERI text, |
| 4095 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4096 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4097 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 4098 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 4099 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4102 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4103 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 4104 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4106 | mApp, subId, callingPackage, callingFeatureId, |
| 4107 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4108 | return null; |
| 4109 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4110 | |
| 4111 | final long identity = Binder.clearCallingIdentity(); |
| 4112 | try { |
| 4113 | final Phone phone = getPhone(subId); |
| 4114 | if (phone != null) { |
| 4115 | return phone.getCdmaEriText(); |
| 4116 | } else { |
| 4117 | return null; |
| 4118 | } |
| 4119 | } finally { |
| 4120 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4121 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4125 | * Returns the CDMA MDN. |
| 4126 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4127 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4128 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4130 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4131 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4132 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4133 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMdn"); |
| 4134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4135 | final long identity = Binder.clearCallingIdentity(); |
| 4136 | try { |
| 4137 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4138 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4139 | return phone.getLine1Number(); |
| 4140 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4141 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4142 | return null; |
| 4143 | } |
| 4144 | } finally { |
| 4145 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | |
| 4149 | /** |
| 4150 | * Returns the CDMA MIN. |
| 4151 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4152 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4153 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4155 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4156 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4157 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4158 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaMin"); |
| 4159 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | final long identity = Binder.clearCallingIdentity(); |
| 4161 | try { |
| 4162 | final Phone phone = getPhone(subId); |
| 4163 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 4164 | return phone.getCdmaMin(); |
| 4165 | } else { |
| 4166 | return null; |
| 4167 | } |
| 4168 | } finally { |
| 4169 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4170 | } |
| 4171 | } |
| 4172 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4173 | @Override |
| 4174 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 4175 | INumberVerificationCallback callback, String callingPackage) { |
| 4176 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 4177 | != PERMISSION_GRANTED) { |
| 4178 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 4179 | } |
| 4180 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4181 | |
| 4182 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 4183 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 4184 | throw new SecurityException("Calling package must be configured in the device config: " |
| 4185 | + "calling package: " + callingPackage |
| 4186 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4187 | } |
| 4188 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4189 | enforceTelephonyFeatureWithException(callingPackage, |
| 4190 | PackageManager.FEATURE_TELEPHONY_CALLING, "requestNumberVerification"); |
| 4191 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4192 | if (range == null) { |
| 4193 | throw new NullPointerException("Range must be non-null"); |
| 4194 | } |
| 4195 | |
| 4196 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4197 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4198 | |
| 4199 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4200 | } |
| 4201 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4202 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4203 | * Returns true if CDMA provisioning needs to run. |
| 4204 | */ |
| 4205 | public boolean needsOtaServiceProvisioning() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4206 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4207 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "needsOtaServiceProvisioning"); |
| 4208 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4209 | final long identity = Binder.clearCallingIdentity(); |
| 4210 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4211 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(identity); |
| 4214 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4218 | * Sets the voice mail number of a given subId. |
| 4219 | */ |
| 4220 | @Override |
| 4221 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4222 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4223 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4224 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4225 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4226 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceMailNumber"); |
| 4227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | final long identity = Binder.clearCallingIdentity(); |
| 4229 | try { |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 4230 | Boolean success = (Boolean) sendRequest( |
| 4231 | CMD_SET_VOICEMAIL_NUMBER, |
| 4232 | new Pair<String, String>(alphaTag, number), |
| 4233 | new Integer(subId), |
| 4234 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
| 4235 | if (success == null) return false; // most likely due to a timeout |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4236 | return success; |
| 4237 | } finally { |
| 4238 | Binder.restoreCallingIdentity(identity); |
| 4239 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4240 | } |
| 4241 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4242 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4243 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4244 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4245 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4246 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4247 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4248 | throw new SecurityException("caller must be system dialer"); |
| 4249 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4251 | enforceTelephonyFeatureWithException(callingPackage, |
| 4252 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailSettings"); |
| 4253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | final long identity = Binder.clearCallingIdentity(); |
| 4255 | try { |
| 4256 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4257 | if (phoneAccountHandle == null) { |
| 4258 | return null; |
| 4259 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4260 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | } finally { |
| 4262 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4263 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4267 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4268 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4269 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4270 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4271 | mApp, subId, callingPackage, callingFeatureId, |
| 4272 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4273 | return null; |
| 4274 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4275 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4276 | enforceTelephonyFeatureWithException(callingPackage, |
| 4277 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVisualVoicemailPackageName"); |
| 4278 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4281 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4282 | } finally { |
| 4283 | Binder.restoreCallingIdentity(identity); |
| 4284 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4288 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4289 | VisualVoicemailSmsFilterSettings settings) { |
| 4290 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 1c55f99 | 2024-06-06 22:34:33 +0000 | [diff] [blame] | 4291 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4292 | enforceTelephonyFeatureWithException(callingPackage, |
| 4293 | PackageManager.FEATURE_TELEPHONY_CALLING, "enableVisualVoicemailSmsFilter"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | final long identity = Binder.clearCallingIdentity(); |
| 4295 | try { |
| 4296 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4297 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4298 | } finally { |
| 4299 | Binder.restoreCallingIdentity(identity); |
| 4300 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4304 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4305 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Thomas Stuart | 9aee7c7 | 2024-06-28 17:33:03 +0000 | [diff] [blame] | 4306 | enforceVisualVoicemailPackage(callingPackage, subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4307 | enforceTelephonyFeatureWithException(callingPackage, |
| 4308 | PackageManager.FEATURE_TELEPHONY_CALLING, "disableVisualVoicemailSmsFilter"); |
| 4309 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
| 4312 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4313 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
| 4316 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4320 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4321 | String callingPackage, int subId) { |
| 4322 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4323 | |
| 4324 | final long identity = Binder.clearCallingIdentity(); |
| 4325 | try { |
| 4326 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4327 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | } finally { |
| 4329 | Binder.restoreCallingIdentity(identity); |
| 4330 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4334 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4335 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | |
| 4337 | final long identity = Binder.clearCallingIdentity(); |
| 4338 | try { |
| 4339 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4340 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | } finally { |
| 4342 | Binder.restoreCallingIdentity(identity); |
| 4343 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4347 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4348 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4349 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4350 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4351 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4352 | enforceSendSmsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4353 | |
| 4354 | enforceTelephonyFeatureWithException(callingPackage, |
| 4355 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendVisualVoicemailSmsForSubscriber"); |
| 4356 | |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4357 | SmsController smsController = PhoneFactory.getSmsController(); |
Nikhil Kumar | deebd75 | 2024-08-14 14:49:06 +0100 | [diff] [blame] | 4358 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, |
| 4359 | Binder.getCallingUserHandle().getIdentifier(), callingAttributionTag, subId, number, |
| 4360 | port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4361 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4362 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4363 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4364 | * Sets the voice activation state of a given subId. |
| 4365 | */ |
| 4366 | @Override |
| 4367 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4369 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4371 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4372 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoiceActivationState"); |
| 4373 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
| 4376 | final Phone phone = getPhone(subId); |
| 4377 | if (phone != null) { |
| 4378 | phone.setVoiceActivationState(activationState); |
| 4379 | } else { |
| 4380 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4381 | } |
| 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | /** |
| 4388 | * Sets the data activation state of a given subId. |
| 4389 | */ |
| 4390 | @Override |
| 4391 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4392 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4393 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4394 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4395 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4396 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataActivationState"); |
| 4397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4398 | final long identity = Binder.clearCallingIdentity(); |
| 4399 | try { |
| 4400 | final Phone phone = getPhone(subId); |
| 4401 | if (phone != null) { |
| 4402 | phone.setDataActivationState(activationState); |
| 4403 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4404 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | } |
| 4406 | } finally { |
| 4407 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4408 | } |
| 4409 | } |
| 4410 | |
| 4411 | /** |
| 4412 | * Returns the voice activation state of a given subId. |
| 4413 | */ |
| 4414 | @Override |
| 4415 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4416 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4417 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4418 | enforceTelephonyFeatureWithException(callingPackage, |
| 4419 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceActivationState"); |
| 4420 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4421 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4422 | final long identity = Binder.clearCallingIdentity(); |
| 4423 | try { |
| 4424 | if (phone != null) { |
| 4425 | return phone.getVoiceActivationState(); |
| 4426 | } else { |
| 4427 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4428 | } |
| 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | /** |
| 4435 | * Returns the data activation state of a given subId. |
| 4436 | */ |
| 4437 | @Override |
| 4438 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4439 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4440 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4441 | enforceTelephonyFeatureWithException(callingPackage, |
| 4442 | PackageManager.FEATURE_TELEPHONY_DATA, "getDataActivationState"); |
| 4443 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4444 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4445 | final long identity = Binder.clearCallingIdentity(); |
| 4446 | try { |
| 4447 | if (phone != null) { |
| 4448 | return phone.getDataActivationState(); |
| 4449 | } else { |
| 4450 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4451 | } |
| 4452 | } finally { |
| 4453 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4458 | * Returns the unread count of voicemails for a subId |
| 4459 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4460 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4461 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4462 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4463 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4464 | mApp, subId, callingPackage, callingFeatureId, |
| 4465 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4466 | return 0; |
| 4467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | final long identity = Binder.clearCallingIdentity(); |
| 4469 | try { |
| 4470 | final Phone phone = getPhone(subId); |
| 4471 | if (phone != null) { |
| 4472 | return phone.getVoiceMessageCount(); |
| 4473 | } else { |
| 4474 | return 0; |
| 4475 | } |
| 4476 | } finally { |
| 4477 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4482 | * returns true, if the device is in a state where both voice and data |
| 4483 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4484 | */ |
| 4485 | @Override |
| 4486 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4487 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4488 | PackageManager.FEATURE_TELEPHONY_DATA, "isConcurrentVoiceAndDataAllowed"); |
| 4489 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | final long identity = Binder.clearCallingIdentity(); |
| 4491 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4492 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4493 | } finally { |
| 4494 | Binder.restoreCallingIdentity(identity); |
| 4495 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4499 | * Send the dialer code if called from the current default dialer or the caller has |
| 4500 | * carrier privilege. |
| 4501 | * @param inputCode The dialer code to send |
| 4502 | */ |
| 4503 | @Override |
| 4504 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4505 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4506 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4507 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4508 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4509 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4510 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4511 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4512 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4513 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4514 | enforceTelephonyFeatureWithException(callingPackage, |
| 4515 | PackageManager.FEATURE_TELEPHONY_CALLING, "sendDialerSpecialCode"); |
| 4516 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4519 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | } finally { |
| 4521 | Binder.restoreCallingIdentity(identity); |
| 4522 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4523 | } |
| 4524 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4525 | @Override |
| 4526 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4527 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4528 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4529 | mApp, subId, "getNetworkSelectionMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4530 | |
| 4531 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4532 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkSelectionMode"); |
| 4533 | |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4534 | final long identity = Binder.clearCallingIdentity(); |
| 4535 | try { |
| 4536 | if (!isActiveSubscription(subId)) { |
| 4537 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4538 | } |
| 4539 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4540 | } finally { |
| 4541 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4542 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4543 | } |
| 4544 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4545 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4546 | public boolean isInEmergencySmsMode() { |
| 4547 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4548 | |
| 4549 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4550 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "isInEmergencySmsMode"); |
| 4551 | |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4552 | final long identity = Binder.clearCallingIdentity(); |
| 4553 | try { |
| 4554 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4555 | if (phone.isInEmergencySmsMode()) { |
| 4556 | return true; |
| 4557 | } |
| 4558 | } |
| 4559 | } finally { |
| 4560 | Binder.restoreCallingIdentity(identity); |
| 4561 | } |
| 4562 | return false; |
| 4563 | } |
| 4564 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4565 | /** |
| 4566 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4567 | * @param subId The subscription to use to check the configuration. |
| 4568 | * @param c The callback that will be used to send the result. |
| 4569 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4570 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4571 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4572 | throws RemoteException { |
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, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4575 | |
| 4576 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4577 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4578 | "IMS not available on device."); |
| 4579 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4580 | final long token = Binder.clearCallingIdentity(); |
| 4581 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4582 | int slotId = getSlotIndexOrException(subId); |
| 4583 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4584 | |
| 4585 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4586 | if (controller != null) { |
| 4587 | ImsManager imsManager = controller.getImsManager(subId); |
| 4588 | if (imsManager != null) { |
| 4589 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4590 | } else { |
| 4591 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4592 | } |
| 4593 | } else { |
| 4594 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4595 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4596 | } catch (ImsException e) { |
| 4597 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(token); |
| 4600 | } |
| 4601 | } |
| 4602 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4603 | /** |
| 4604 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4605 | * @param subId The subscription to use to check the configuration. |
| 4606 | * @param c The callback that will be used to send the result. |
| 4607 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4608 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4609 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4610 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4611 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4612 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4613 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4614 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4615 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4616 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4617 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4618 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4619 | if (controller != null) { |
| 4620 | ImsManager imsManager = controller.getImsManager(subId); |
| 4621 | if (imsManager != null) { |
| 4622 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4623 | } else { |
| 4624 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4625 | + "is inactive, ignoring unregister."); |
| 4626 | // If the ImsManager is not valid, just return, since the callback |
| 4627 | // will already have been removed internally. |
| 4628 | } |
| 4629 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4630 | } finally { |
| 4631 | Binder.restoreCallingIdentity(token); |
| 4632 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4635 | /** |
Hidayat Khan | 99ea48f | 2023-12-11 04:37:45 +0000 | [diff] [blame] | 4636 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4637 | * @param subId The subscription to use to check the configuration. |
| 4638 | * @param c The callback that will be used to send the result. |
| 4639 | */ |
| 4640 | @Override |
| 4641 | public void registerImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4642 | throws RemoteException { |
| 4643 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4644 | mApp, subId, "registerImsEmergencyRegistrationCallback"); |
| 4645 | |
| 4646 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4647 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4648 | "IMS not available on device."); |
| 4649 | } |
| 4650 | final long token = Binder.clearCallingIdentity(); |
| 4651 | try { |
| 4652 | int slotId = getSlotIndexOrException(subId); |
| 4653 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4654 | |
| 4655 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4656 | if (controller != null) { |
| 4657 | ImsManager imsManager = controller.getImsManager(subId); |
| 4658 | if (imsManager != null) { |
| 4659 | imsManager.addEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4660 | } else { |
| 4661 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4662 | } |
| 4663 | } else { |
| 4664 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4665 | } |
| 4666 | } catch (ImsException e) { |
| 4667 | throw new ServiceSpecificException(e.getCode()); |
| 4668 | } finally { |
| 4669 | Binder.restoreCallingIdentity(token); |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | /** |
| 4674 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4675 | * @param subId The subscription to use to check the configuration. |
| 4676 | * @param c The callback that will be used to send the result. |
| 4677 | */ |
| 4678 | @Override |
| 4679 | public void unregisterImsEmergencyRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 4680 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4681 | mApp, subId, "unregisterImsEmergencyRegistrationCallback"); |
| 4682 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4683 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4684 | } |
| 4685 | final long token = Binder.clearCallingIdentity(); |
| 4686 | |
| 4687 | try { |
| 4688 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4689 | if (controller != null) { |
| 4690 | ImsManager imsManager = controller.getImsManager(subId); |
| 4691 | if (imsManager != null) { |
| 4692 | imsManager.removeEmergencyRegistrationCallbackForSubscription(c, subId); |
| 4693 | } else { |
| 4694 | Log.i(LOG_TAG, "unregisterImsEmergencyRegistrationCallback: " + subId |
| 4695 | + "is inactive, ignoring unregister."); |
| 4696 | // If the ImsManager is not valid, just return, since the callback |
| 4697 | // will already have been removed internally. |
| 4698 | } |
| 4699 | } |
| 4700 | } finally { |
| 4701 | Binder.restoreCallingIdentity(token); |
| 4702 | } |
| 4703 | } |
| 4704 | |
| 4705 | /** |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4706 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4707 | */ |
| 4708 | @Override |
| 4709 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4710 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4711 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4712 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4713 | "IMS not available on device."); |
| 4714 | } |
| 4715 | final long token = Binder.clearCallingIdentity(); |
| 4716 | try { |
| 4717 | Phone phone = getPhone(subId); |
| 4718 | if (phone == null) { |
| 4719 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4720 | + subId + "'"); |
| 4721 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4722 | } |
| 4723 | phone.getImsRegistrationState(regState -> { |
| 4724 | try { |
| 4725 | consumer.accept((regState == null) |
| 4726 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4727 | } catch (RemoteException e) { |
| 4728 | // Ignore if the remote process is no longer available to call back. |
| 4729 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4730 | } |
| 4731 | }); |
| 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(token); |
| 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | /** |
| 4738 | * Get the transport type for the IMS service registration state. |
| 4739 | */ |
| 4740 | @Override |
| 4741 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4742 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4743 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4744 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4746 | "IMS not available on device."); |
| 4747 | } |
| 4748 | final long token = Binder.clearCallingIdentity(); |
| 4749 | try { |
| 4750 | Phone phone = getPhone(subId); |
| 4751 | if (phone == null) { |
| 4752 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4753 | + subId + "'"); |
| 4754 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4755 | } |
| 4756 | phone.getImsRegistrationTech(regTech -> { |
| 4757 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4758 | int regTechConverted = (regTech == null) |
| 4759 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4760 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4761 | regTechConverted); |
| 4762 | try { |
| 4763 | consumer.accept(regTechConverted); |
| 4764 | } catch (RemoteException e) { |
| 4765 | // Ignore if the remote process is no longer available to call back. |
| 4766 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4767 | } |
| 4768 | }); |
| 4769 | } finally { |
| 4770 | Binder.restoreCallingIdentity(token); |
| 4771 | } |
| 4772 | } |
| 4773 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4774 | /** |
| 4775 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4776 | * @param subId The subscription to use to check the configuration. |
| 4777 | * @param c The callback that will be used to send the result. |
| 4778 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4779 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4780 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4781 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4782 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4783 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4784 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4785 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4786 | "IMS not available on device."); |
| 4787 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4788 | final long token = Binder.clearCallingIdentity(); |
| 4789 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4790 | int slotId = getSlotIndexOrException(subId); |
| 4791 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4792 | |
| 4793 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4794 | if (controller != null) { |
| 4795 | ImsManager imsManager = controller.getImsManager(subId); |
| 4796 | if (imsManager != null) { |
| 4797 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4798 | } else { |
| 4799 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4800 | } |
| 4801 | } else { |
| 4802 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4803 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4804 | } catch (ImsException e) { |
| 4805 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4806 | } finally { |
| 4807 | Binder.restoreCallingIdentity(token); |
| 4808 | } |
| 4809 | } |
| 4810 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4811 | /** |
| 4812 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4813 | * @param subId The subscription to use to check the configuration. |
| 4814 | * @param c The callback that will be used to send the result. |
| 4815 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4816 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4817 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4818 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4819 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4820 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4821 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4822 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4823 | |
| 4824 | final long token = Binder.clearCallingIdentity(); |
| 4825 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4826 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4827 | if (controller != null) { |
| 4828 | ImsManager imsManager = controller.getImsManager(subId); |
| 4829 | if (imsManager != null) { |
| 4830 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4831 | } else { |
| 4832 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4833 | + " is inactive, ignoring unregister."); |
| 4834 | // If the ImsManager is not valid, just return, since the callback |
| 4835 | // will already have been removed internally. |
| 4836 | } |
| 4837 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4838 | } finally { |
| 4839 | Binder.restoreCallingIdentity(token); |
| 4840 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4844 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4845 | enforceReadPrivilegedPermission("isCapable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4846 | |
| 4847 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4848 | FEATURE_TELEPHONY_IMS, "isCapable"); |
| 4849 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4850 | final long token = Binder.clearCallingIdentity(); |
| 4851 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4852 | int slotId = getSlotIndexOrException(subId); |
| 4853 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4854 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4855 | } catch (com.android.ims.ImsException e) { |
| 4856 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4857 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4858 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4859 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4860 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(token); |
| 4863 | } |
| 4864 | } |
| 4865 | |
| 4866 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4867 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4868 | enforceReadPrivilegedPermission("isAvailable"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4869 | |
| 4870 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4871 | FEATURE_TELEPHONY_IMS, "isAvailable"); |
| 4872 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4873 | final long token = Binder.clearCallingIdentity(); |
| 4874 | try { |
| 4875 | Phone phone = getPhone(subId); |
| 4876 | if (phone == null) return false; |
| 4877 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4878 | } catch (com.android.ims.ImsException e) { |
| 4879 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4880 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4881 | } finally { |
| 4882 | Binder.restoreCallingIdentity(token); |
| 4883 | } |
| 4884 | } |
| 4885 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4886 | /** |
| 4887 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4888 | * subscription. |
| 4889 | * @param subId The subscription to use to check the configuration. |
| 4890 | * @param callback The callback that will be used to send the result. |
| 4891 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4892 | * @param transportType The transport type of the MmTelFeature capability. |
| 4893 | */ |
| 4894 | @Override |
| 4895 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4896 | int transportType) { |
| 4897 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4898 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4899 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4900 | "IMS not available on device."); |
| 4901 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4902 | final long token = Binder.clearCallingIdentity(); |
| 4903 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4904 | int slotId = getSlotIndex(subId); |
| 4905 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4906 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4907 | + subId + "'"); |
| 4908 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4909 | } |
| 4910 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4911 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4912 | transportType, aBoolean -> { |
| 4913 | try { |
| 4914 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4915 | } catch (RemoteException e) { |
| 4916 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4917 | + "running. Ignore"); |
| 4918 | } |
| 4919 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4920 | } catch (ImsException e) { |
| 4921 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(token); |
| 4924 | } |
| 4925 | } |
| 4926 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4927 | /** |
| 4928 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4929 | * @param subId The subscription to use to check the configuration. |
| 4930 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4931 | @Override |
| 4932 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4933 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4934 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4935 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4936 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4937 | FEATURE_TELEPHONY_IMS, "isAdvancedCallingSettingEnabled"); |
| 4938 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4939 | final long token = Binder.clearCallingIdentity(); |
| 4940 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4941 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4942 | // 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] | 4943 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4944 | } catch (ImsException e) { |
| 4945 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4946 | } finally { |
| 4947 | Binder.restoreCallingIdentity(token); |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4952 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4953 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4954 | "setAdvancedCallingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4955 | |
| 4956 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4957 | FEATURE_TELEPHONY_IMS, "setAdvancedCallingSettingEnabled"); |
| 4958 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); |
| 4960 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4961 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4962 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4963 | // 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] | 4964 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4965 | } catch (ImsException e) { |
| 4966 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4967 | } finally { |
| 4968 | Binder.restoreCallingIdentity(identity); |
| 4969 | } |
| 4970 | } |
| 4971 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4972 | /** |
| 4973 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4974 | * @param subId The subscription to use to check the configuration. |
| 4975 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4976 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4977 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4978 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4979 | mApp, subId, "isVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 4980 | |
| 4981 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 4982 | FEATURE_TELEPHONY_IMS, "isVtSettingEnabled"); |
| 4983 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4984 | final long identity = Binder.clearCallingIdentity(); |
| 4985 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4986 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4987 | // 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] | 4988 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4989 | } catch (ImsException e) { |
| 4990 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4991 | } finally { |
| 4992 | Binder.restoreCallingIdentity(identity); |
| 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4997 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4999 | "setVtSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5000 | |
| 5001 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5002 | FEATURE_TELEPHONY_IMS, "setVtSettingEnabled"); |
| 5003 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5004 | final long identity = Binder.clearCallingIdentity(); |
| 5005 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5006 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5007 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5008 | // 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] | 5009 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5010 | } catch (ImsException e) { |
| 5011 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
| 5014 | } |
| 5015 | } |
| 5016 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5017 | /** |
| 5018 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5019 | * @param subId The subscription to use to check the configuration. |
| 5020 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5021 | @Override |
| 5022 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5023 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5024 | mApp, subId, "isVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5025 | |
| 5026 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5027 | FEATURE_TELEPHONY_IMS, "isVoWiFiSettingEnabled"); |
| 5028 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5029 | final long identity = Binder.clearCallingIdentity(); |
| 5030 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5031 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5032 | // 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] | 5033 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5034 | } catch (ImsException e) { |
| 5035 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5036 | } finally { |
| 5037 | Binder.restoreCallingIdentity(identity); |
| 5038 | } |
| 5039 | } |
| 5040 | |
| 5041 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5042 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5044 | "setVoWiFiSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5045 | |
| 5046 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5047 | FEATURE_TELEPHONY_IMS, "setVoWiFiSettingEnabled"); |
| 5048 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5049 | final long identity = Binder.clearCallingIdentity(); |
| 5050 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5051 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5052 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5053 | // 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] | 5054 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5055 | } catch (ImsException e) { |
| 5056 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5057 | } finally { |
| 5058 | Binder.restoreCallingIdentity(identity); |
| 5059 | } |
| 5060 | } |
| 5061 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5062 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5063 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 5064 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5065 | * @param subId The subscription to use to check the configuration. |
| 5066 | */ |
| 5067 | @Override |
| 5068 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5069 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5070 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5071 | |
| 5072 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5073 | FEATURE_TELEPHONY_IMS, "isCrossSimCallingEnabledByUser"); |
| 5074 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5075 | final long identity = Binder.clearCallingIdentity(); |
| 5076 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5077 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5078 | // 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] | 5079 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5080 | } catch (ImsException e) { |
| 5081 | throw new ServiceSpecificException(e.getCode()); |
| 5082 | } finally { |
| 5083 | Binder.restoreCallingIdentity(identity); |
| 5084 | } |
| 5085 | } |
| 5086 | |
| 5087 | /** |
| 5088 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 5089 | * Requires MODIFY_PHONE_STATE permission. |
| 5090 | * @param subId The subscription to use to check the configuration. |
| 5091 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 5092 | * false otherwise |
| 5093 | */ |
| 5094 | @Override |
| 5095 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 5096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5097 | "setCrossSimCallingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5098 | |
| 5099 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5100 | FEATURE_TELEPHONY_IMS, "setCrossSimCallingEnabled"); |
| 5101 | |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5102 | final long identity = Binder.clearCallingIdentity(); |
| 5103 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5104 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5105 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5106 | // 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] | 5107 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 5108 | } catch (ImsException e) { |
| 5109 | throw new ServiceSpecificException(e.getCode()); |
| 5110 | } finally { |
| 5111 | Binder.restoreCallingIdentity(identity); |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5116 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5117 | * @param subId The subscription to use to check the configuration. |
| 5118 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5119 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5120 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5121 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5122 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5123 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5124 | |
| 5125 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5126 | FEATURE_TELEPHONY_IMS, "isVoWiFiRoamingSettingEnabled"); |
| 5127 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5128 | final long identity = Binder.clearCallingIdentity(); |
| 5129 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5130 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5131 | // 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] | 5132 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5133 | } catch (ImsException e) { |
| 5134 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5141 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 5143 | "setVoWiFiRoamingSettingEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5144 | |
| 5145 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5146 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingSettingEnabled"); |
| 5147 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5148 | final long identity = Binder.clearCallingIdentity(); |
| 5149 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5150 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5151 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5152 | // 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] | 5153 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5154 | } catch (ImsException e) { |
| 5155 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
| 5158 | } |
| 5159 | } |
| 5160 | |
| 5161 | @Override |
| 5162 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 5163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5164 | "setVoWiFiNonPersistent"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5165 | |
| 5166 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5167 | FEATURE_TELEPHONY_IMS, "setVoWiFiNonPersistent"); |
| 5168 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5169 | final long identity = Binder.clearCallingIdentity(); |
| 5170 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5171 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5172 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5173 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5174 | } catch (ImsException e) { |
| 5175 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5176 | } finally { |
| 5177 | Binder.restoreCallingIdentity(identity); |
| 5178 | } |
| 5179 | } |
| 5180 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5181 | /** |
| 5182 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5183 | * @param subId The subscription to use to check the configuration. |
| 5184 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5185 | @Override |
| 5186 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5187 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5188 | mApp, subId, "getVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5189 | |
| 5190 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5191 | FEATURE_TELEPHONY_IMS, "getVoWiFiModeSetting"); |
| 5192 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5193 | final long identity = Binder.clearCallingIdentity(); |
| 5194 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5195 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5196 | // 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] | 5197 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5198 | } catch (ImsException e) { |
| 5199 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | @Override |
| 5206 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 5207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5208 | "setVoWiFiModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5209 | |
| 5210 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5211 | FEATURE_TELEPHONY_IMS, "setVoWiFiModeSetting"); |
| 5212 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5213 | final long identity = Binder.clearCallingIdentity(); |
| 5214 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5215 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5216 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5217 | // 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] | 5218 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5219 | } catch (ImsException e) { |
| 5220 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5221 | } finally { |
| 5222 | Binder.restoreCallingIdentity(identity); |
| 5223 | } |
| 5224 | } |
| 5225 | |
| 5226 | @Override |
| 5227 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 5228 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5229 | |
| 5230 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5231 | FEATURE_TELEPHONY_IMS, "getVoWiFiRoamingModeSetting"); |
| 5232 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5233 | final long identity = Binder.clearCallingIdentity(); |
| 5234 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5235 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5236 | // 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] | 5237 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5238 | } catch (ImsException e) { |
| 5239 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5240 | } finally { |
| 5241 | Binder.restoreCallingIdentity(identity); |
| 5242 | } |
| 5243 | } |
| 5244 | |
| 5245 | @Override |
| 5246 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 5247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5248 | "setVoWiFiRoamingModeSetting"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5249 | |
| 5250 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5251 | FEATURE_TELEPHONY_IMS, "setVoWiFiRoamingModeSetting"); |
| 5252 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5255 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5256 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5257 | // 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] | 5258 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5259 | } catch (ImsException e) { |
| 5260 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5261 | } finally { |
| 5262 | Binder.restoreCallingIdentity(identity); |
| 5263 | } |
| 5264 | } |
| 5265 | |
| 5266 | @Override |
| 5267 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 5268 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5269 | "setRttCapabilityEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5270 | |
| 5271 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5272 | FEATURE_TELEPHONY_IMS, "setRttCapabilitySetting"); |
| 5273 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5274 | final long identity = Binder.clearCallingIdentity(); |
| 5275 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5276 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5277 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 5278 | // 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] | 5279 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5280 | } catch (ImsException e) { |
| 5281 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
| 5284 | } |
| 5285 | } |
| 5286 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 5287 | /** |
| 5288 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 5289 | * @param subId The subscription to use to check the configuration. |
| 5290 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5291 | @Override |
| 5292 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5293 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 5294 | mApp, subId, "isTtyOverVolteEnabled"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5295 | |
| 5296 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5297 | FEATURE_TELEPHONY_IMS, "isTtyOverVolteEnabled"); |
| 5298 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5299 | final long identity = Binder.clearCallingIdentity(); |
| 5300 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5301 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 5302 | // 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] | 5303 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5304 | } catch (ImsException e) { |
| 5305 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5306 | } finally { |
| 5307 | Binder.restoreCallingIdentity(identity); |
| 5308 | } |
| 5309 | } |
| 5310 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5311 | @Override |
| 5312 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5313 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5314 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5315 | final long identity = Binder.clearCallingIdentity(); |
| 5316 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5317 | if (!isImsAvailableOnDevice()) { |
| 5318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5319 | "IMS not available on device."); |
| 5320 | } |
| 5321 | int slotId = getSlotIndexOrException(subId); |
| 5322 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5323 | |
| 5324 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5325 | if (controller != null) { |
| 5326 | ImsManager imsManager = controller.getImsManager(subId); |
| 5327 | if (imsManager != null) { |
| 5328 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 5329 | } else { |
| 5330 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 5331 | } |
| 5332 | } else { |
| 5333 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5334 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5335 | } catch (ImsException e) { |
| 5336 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5337 | } finally { |
| 5338 | Binder.restoreCallingIdentity(identity); |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | @Override |
| 5343 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 5344 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5345 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5346 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 5347 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5348 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5349 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5350 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 5351 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 5352 | if (controller != null) { |
| 5353 | ImsManager imsManager = controller.getImsManager(subId); |
| 5354 | if (imsManager != null) { |
| 5355 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 5356 | } else { |
| 5357 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 5358 | + " is inactive, ignoring unregister."); |
| 5359 | // If the ImsManager is not valid, just return, since the callback will already |
| 5360 | // have been removed internally. |
| 5361 | } |
| 5362 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5363 | } finally { |
| 5364 | Binder.restoreCallingIdentity(identity); |
| 5365 | } |
| 5366 | } |
| 5367 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5368 | @Override |
| 5369 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 5370 | IFeatureProvisioningCallback callback) { |
| 5371 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5372 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 5373 | |
| 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5376 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5377 | } |
| 5378 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5379 | try { |
| 5380 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5381 | if (controller == null) { |
| 5382 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5383 | "Device does not support IMS"); |
| 5384 | } |
| 5385 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
| 5388 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | @Override |
| 5392 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5393 | IFeatureProvisioningCallback callback) { |
| 5394 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5395 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5396 | |
| 5397 | final long identity = Binder.clearCallingIdentity(); |
| 5398 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5399 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5400 | } |
| 5401 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5402 | try { |
| 5403 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5404 | if (controller == null) { |
| 5405 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5406 | return; |
| 5407 | } |
| 5408 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
| 5411 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5412 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5413 | |
| 5414 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5416 | message); |
| 5417 | } |
| 5418 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5419 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5420 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5421 | boolean isProvisioned) { |
| 5422 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5423 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5424 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5425 | FEATURE_TELEPHONY_IMS, "setRcsProvisioningStatusForCapability"); |
| 5426 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5427 | final long identity = Binder.clearCallingIdentity(); |
| 5428 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5429 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5430 | if (controller == null) { |
| 5431 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5432 | return; |
| 5433 | } |
| 5434 | controller.setRcsProvisioningStatusForCapability( |
| 5435 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5436 | } finally { |
| 5437 | Binder.restoreCallingIdentity(identity); |
| 5438 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | |
| 5442 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5443 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5444 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5445 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5446 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5447 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5448 | FEATURE_TELEPHONY_IMS, "getRcsProvisioningStatusForCapability"); |
| 5449 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5450 | final long identity = Binder.clearCallingIdentity(); |
| 5451 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5452 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5453 | if (controller == null) { |
| 5454 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5455 | |
| 5456 | // device does not support IMS, this method will return true always. |
| 5457 | return true; |
| 5458 | } |
| 5459 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
| 5463 | } |
| 5464 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5465 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5466 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5467 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5468 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5469 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5470 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5471 | FEATURE_TELEPHONY_IMS, "setImsProvisioningStatusForCapability"); |
| 5472 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5473 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5474 | final long identity = Binder.clearCallingIdentity(); |
| 5475 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5476 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5477 | if (controller == null) { |
| 5478 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5479 | return; |
| 5480 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5481 | controller.setImsProvisioningStatusForCapability(displayPackageName, |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5482 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | @Override |
| 5489 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5490 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5491 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5492 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5493 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5494 | FEATURE_TELEPHONY_IMS, "getImsProvisioningStatusForCapability"); |
| 5495 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5496 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5497 | final long identity = Binder.clearCallingIdentity(); |
| 5498 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5499 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5500 | if (controller == null) { |
| 5501 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5502 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5503 | // device does not support IMS, this method will return true always. |
| 5504 | return true; |
| 5505 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5506 | return controller.getImsProvisioningStatusForCapability(displayPackageName, |
| 5507 | subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5508 | } finally { |
| 5509 | Binder.restoreCallingIdentity(identity); |
| 5510 | } |
| 5511 | } |
| 5512 | |
| 5513 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5514 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5515 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5516 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5517 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5518 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5519 | FEATURE_TELEPHONY_IMS, "isProvisioningRequiredForCapability"); |
| 5520 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5521 | final long identity = Binder.clearCallingIdentity(); |
| 5522 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5523 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5524 | if (controller == null) { |
| 5525 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5526 | |
| 5527 | // device does not support IMS, this method will return false |
| 5528 | return false; |
| 5529 | } |
| 5530 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5533 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5537 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5538 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5539 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5540 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5541 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5542 | FEATURE_TELEPHONY_IMS, "isRcsProvisioningRequiredForCapability"); |
| 5543 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5544 | final long identity = Binder.clearCallingIdentity(); |
| 5545 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5546 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5547 | if (controller == null) { |
| 5548 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5549 | |
| 5550 | // device does not support IMS, this method will return false |
| 5551 | return false; |
| 5552 | } |
| 5553 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5554 | } finally { |
| 5555 | Binder.restoreCallingIdentity(identity); |
| 5556 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5557 | } |
| 5558 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5559 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5560 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5561 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5562 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5563 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5564 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5565 | mApp, subId, "getImsProvisioningInt"); |
| 5566 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5567 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5568 | FEATURE_TELEPHONY_IMS, "getImsProvisioningInt"); |
| 5569 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5570 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5571 | final long identity = Binder.clearCallingIdentity(); |
| 5572 | try { |
| 5573 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5574 | int slotId = getSlotIndex(subId); |
| 5575 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5576 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5577 | + subId + "' for key:" + key); |
| 5578 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5579 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5580 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5581 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5582 | if (controller == null) { |
| 5583 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5584 | |
| 5585 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5586 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5587 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5588 | int retVal = controller.getProvisioningValue(displayPackageName, subId, |
| 5589 | key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5590 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5591 | return retVal; |
| 5592 | } |
| 5593 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5594 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5595 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5596 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5597 | + subId + "' for key:" + key); |
| 5598 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5599 | } finally { |
| 5600 | Binder.restoreCallingIdentity(identity); |
| 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | @Override |
| 5605 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5606 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5607 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5608 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5609 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5610 | mApp, subId, "getImsProvisioningString"); |
| 5611 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5612 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5613 | FEATURE_TELEPHONY_IMS, "getImsProvisioningString"); |
| 5614 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5615 | final long identity = Binder.clearCallingIdentity(); |
| 5616 | try { |
| 5617 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5618 | int slotId = getSlotIndex(subId); |
| 5619 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5620 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5621 | + subId + "' for key:" + key); |
| 5622 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5623 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5624 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5625 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5626 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5627 | + subId + "' for key:" + key); |
| 5628 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5629 | } finally { |
| 5630 | Binder.restoreCallingIdentity(identity); |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | @Override |
| 5635 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5636 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5637 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5638 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5640 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5641 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5642 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5643 | FEATURE_TELEPHONY_IMS, "setImsProvisioningInt"); |
| 5644 | |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5645 | String displayPackageName = getCurrentPackageNameOrPhone(); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5646 | final long identity = Binder.clearCallingIdentity(); |
| 5647 | try { |
| 5648 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5649 | int slotId = getSlotIndex(subId); |
| 5650 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5651 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5652 | + subId + "' for key:" + key); |
| 5653 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5654 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5655 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5656 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5657 | if (controller == null) { |
| 5658 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5659 | |
| 5660 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5661 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5662 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 5663 | int retVal = controller.setProvisioningValue(displayPackageName, subId, key, |
| 5664 | value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5665 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5666 | return retVal; |
| 5667 | } |
| 5668 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5669 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5670 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5671 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5672 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5673 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5674 | } finally { |
| 5675 | Binder.restoreCallingIdentity(identity); |
| 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | @Override |
| 5680 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5681 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5682 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5683 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5685 | "setImsProvisioningString"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5686 | |
| 5687 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5688 | FEATURE_TELEPHONY_IMS, "setImsProvisioningString"); |
| 5689 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5690 | final long identity = Binder.clearCallingIdentity(); |
| 5691 | try { |
| 5692 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5693 | int slotId = getSlotIndex(subId); |
| 5694 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5695 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5696 | + subId + "' for key:" + key); |
| 5697 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5698 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5699 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5700 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5701 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5702 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5703 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5704 | } finally { |
| 5705 | Binder.restoreCallingIdentity(identity); |
| 5706 | } |
| 5707 | } |
| 5708 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5709 | /** |
| 5710 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5711 | * for the given slot ID or no ImsResolver instance has been created. |
| 5712 | * @param slotId The slot ID that the IMS service is created for. |
| 5713 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5714 | */ |
| 5715 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5716 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5717 | ImsFeature.FEATURE_MMTEL)) { |
| 5718 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5719 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5720 | } |
| 5721 | } |
| 5722 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5723 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5724 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5725 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5726 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5727 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5728 | } |
| 5729 | return slotId; |
| 5730 | } |
| 5731 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5732 | private int getSlotIndex(int subId) { |
| 5733 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5734 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5735 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5736 | } |
| 5737 | return slotId; |
| 5738 | } |
| 5739 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5740 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5741 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5742 | */ |
| 5743 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5744 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5745 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5746 | try { |
| 5747 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5748 | } catch (SecurityException se) { |
| 5749 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5750 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5751 | + Binder.getCallingUid()); |
| 5752 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5753 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5754 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5755 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5756 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5757 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5758 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5759 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5760 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5761 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5762 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5763 | enforceTelephonyFeatureWithException(callingPackage, |
| 5764 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getNetworkTypeForSubscriber"); |
| 5765 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | final long identity = Binder.clearCallingIdentity(); |
| 5767 | try { |
| 5768 | final Phone phone = getPhone(subId); |
| 5769 | if (phone != null) { |
| 5770 | return phone.getServiceState().getDataNetworkType(); |
| 5771 | } else { |
| 5772 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5773 | } |
| 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | /** |
| 5780 | * Returns the data network type |
| 5781 | */ |
| 5782 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5783 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5784 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5785 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5786 | } |
| 5787 | |
| 5788 | /** |
| 5789 | * Returns the data network type for a subId |
| 5790 | */ |
| 5791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5792 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5793 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5794 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5795 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5796 | mApp, functionName)) { |
| 5797 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5798 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5799 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5800 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5801 | } |
| 5802 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5803 | enforceTelephonyFeatureWithException(callingPackage, |
| 5804 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getDataNetworkTypeForSubscriber"); |
| 5805 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | final long identity = Binder.clearCallingIdentity(); |
| 5807 | try { |
| 5808 | final Phone phone = getPhone(subId); |
| 5809 | if (phone != null) { |
| 5810 | return phone.getServiceState().getDataNetworkType(); |
| 5811 | } else { |
| 5812 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5813 | } |
| 5814 | } finally { |
| 5815 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5816 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5820 | * Returns the Voice network type for a subId |
| 5821 | */ |
| 5822 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5823 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5824 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5825 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5826 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5827 | mApp, functionName)) { |
| 5828 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5829 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5830 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5831 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5832 | } |
| 5833 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5834 | enforceTelephonyFeatureWithException(callingPackage, |
| 5835 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoiceNetworkTypeForSubscriber"); |
| 5836 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | final long identity = Binder.clearCallingIdentity(); |
| 5838 | try { |
| 5839 | final Phone phone = getPhone(subId); |
| 5840 | if (phone != null) { |
| 5841 | return phone.getServiceState().getVoiceNetworkType(); |
| 5842 | } else { |
| 5843 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5844 | } |
| 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5847 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | /** |
| 5851 | * @return true if a ICC card is present |
| 5852 | */ |
| 5853 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5854 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5855 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5856 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5860 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5861 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5862 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5863 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 5864 | if (!mApp.getResources().getBoolean( |
| 5865 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 5866 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 5867 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "hasIccCardUsingSlotIndex"); |
| 5868 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | final long identity = Binder.clearCallingIdentity(); |
| 5871 | try { |
| 5872 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5873 | if (phone != null) { |
| 5874 | return phone.getIccCard().hasIccCard(); |
| 5875 | } else { |
| 5876 | return false; |
| 5877 | } |
| 5878 | } finally { |
| 5879 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5880 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5881 | } |
| 5882 | |
| 5883 | /** |
| 5884 | * Return if the current radio is LTE on CDMA. This |
| 5885 | * is a tri-state return value as for a period of time |
| 5886 | * the mode may be unknown. |
| 5887 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5888 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5889 | * @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] | 5890 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5891 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5892 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5893 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5894 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5895 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5898 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5899 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5900 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5901 | try { |
| 5902 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5903 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5904 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5905 | } |
| 5906 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5907 | enforceTelephonyFeatureWithException(callingPackage, |
| 5908 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getLteOnCdmaModeForSubscriber"); |
| 5909 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | final long identity = Binder.clearCallingIdentity(); |
| 5911 | try { |
| 5912 | final Phone phone = getPhone(subId); |
| 5913 | if (phone == null) { |
| 5914 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5915 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5916 | return TelephonyProperties.lte_on_cdma_device() |
| 5917 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | } |
| 5919 | } finally { |
| 5920 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5921 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5922 | } |
| 5923 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5924 | /** |
| 5925 | * {@hide} |
| 5926 | * Returns Default subId, 0 in the case of single standby. |
| 5927 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5928 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5929 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5930 | } |
| 5931 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5932 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5933 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5934 | } |
| 5935 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5936 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5937 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5938 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5939 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5940 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 5941 | return getSubscriptionManagerService().isActiveSubId(subId, |
| 5942 | mApp.getOpPackageName(), mApp.getFeatureId()); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5943 | } |
| 5944 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5945 | /** |
| 5946 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5947 | */ |
| 5948 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5951 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5953 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
| 5956 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | /** |
| 5960 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5961 | */ |
| 5962 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | final long identity = Binder.clearCallingIdentity(); |
| 5964 | try { |
| 5965 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5966 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5967 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5968 | } finally { |
| 5969 | Binder.restoreCallingIdentity(identity); |
| 5970 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5971 | } |
| 5972 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5973 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5974 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5975 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5976 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5977 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5978 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5979 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5980 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5981 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5982 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5983 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5984 | } |
| 5985 | return PhoneFactory.getPhone(phoneId); |
| 5986 | } |
| 5987 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5988 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5989 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5990 | @NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5991 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5992 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5993 | /*message=*/ "iccOpenLogicalChannel"); |
| 5994 | |
| 5995 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5996 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5997 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5998 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 5999 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6000 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccOpenLogicalChannel"); |
| 6001 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6002 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6003 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6004 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6005 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 6006 | @NonNull IccLogicalChannelRequest request, String message) { |
| 6007 | Phone phone; |
| 6008 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 6009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6010 | mApp, request.subId, message); |
| 6011 | phone = getPhoneFromSubId(request.subId); |
| 6012 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6013 | enforceModifyPermission(); |
| 6014 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 6015 | } else { |
| 6016 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6017 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6018 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6022 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | final long identity = Binder.clearCallingIdentity(); |
| 6024 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6025 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6026 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6027 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6028 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6029 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 6030 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | loge("The calling package is not allowed to access ISD-R."); |
| 6032 | throw new SecurityException( |
| 6033 | "The calling package is not allowed to access ISD-R."); |
| 6034 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6035 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 6036 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6037 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6038 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 6039 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6040 | return response; |
| 6041 | } finally { |
| 6042 | Binder.restoreCallingIdentity(identity); |
| 6043 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6047 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6048 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6049 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccCloseLogicalChannel"); |
| 6050 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6051 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 6052 | /*message=*/"iccCloseLogicalChannel"); |
| 6053 | |
| 6054 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 6055 | |
| 6056 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6057 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6058 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6059 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 6060 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6061 | // before this feature is enabled, this API should only return false if |
| 6062 | // the operation fails instead of throwing runtime exception for |
| 6063 | // backward-compatibility. |
| 6064 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 6065 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6066 | final long identity = Binder.clearCallingIdentity(); |
| 6067 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6068 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 6069 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6071 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6072 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6073 | Boolean success = false; |
| 6074 | if (result instanceof RuntimeException) { |
| 6075 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 6076 | if (shouldThrowExceptionOnFailure) { |
| 6077 | throw (RuntimeException) result; |
| 6078 | } else { |
| 6079 | return false; |
| 6080 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 6081 | } else if (result instanceof Boolean) { |
| 6082 | success = (Boolean) result; |
| 6083 | } else { |
| 6084 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 6085 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 6086 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | return success; |
| 6088 | } finally { |
| 6089 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6090 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6094 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6095 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6097 | mApp, subId, "iccTransmitApduLogicalChannel"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6098 | |
| 6099 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6100 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduLogicalChannel"); |
| 6101 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6102 | if (DBG) { |
| 6103 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 6104 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 6105 | + p3 + " data=" + data); |
| 6106 | } |
| 6107 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 6108 | command, p1, p2, p3, data); |
| 6109 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6110 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6111 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6112 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6113 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6114 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6115 | |
| 6116 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6117 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 6118 | "iccTransmitApduLogicalChannelBySlot"); |
| 6119 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6120 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6121 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6122 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 6123 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6124 | } |
| 6125 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6126 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 6127 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 6131 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6132 | final long identity = Binder.clearCallingIdentity(); |
| 6133 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 6134 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | return ""; |
| 6136 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6138 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6139 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 6140 | null /* workSource */); |
| 6141 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | // Append the returned status code to the end of the response payload. |
| 6144 | String s = Integer.toHexString( |
| 6145 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6146 | if (response.payload != null) { |
| 6147 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6148 | } |
| 6149 | return s; |
| 6150 | } finally { |
| 6151 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6152 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 6153 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6154 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6155 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6156 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 6157 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6158 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6159 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6160 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6161 | |
| 6162 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6163 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannel"); |
| 6164 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6165 | if (DBG) { |
| 6166 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 6167 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 6168 | } |
| 6169 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 6170 | cla, command, p1, p2, p3, data); |
| 6171 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6172 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6173 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6174 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6175 | 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] | 6176 | enforceModifyPermission(); |
| 6177 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6178 | |
| 6179 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6180 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccTransmitApduBasicChannelBySlot"); |
| 6181 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6182 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6183 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6184 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 6185 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 6189 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 6190 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | // open APDU basic channel assuming the caller has sufficient permissions |
| 6194 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 6195 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6196 | final long identity = Binder.clearCallingIdentity(); |
| 6197 | try { |
| 6198 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 6199 | && TextUtils.equals(ISDR_AID, data)) { |
| 6200 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6201 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 6202 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6203 | if (bestComponent == null |
| 6204 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 6205 | loge("The calling package is not allowed to select ISD-R."); |
| 6206 | throw new SecurityException( |
| 6207 | "The calling package is not allowed to select ISD-R."); |
| 6208 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6209 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 6210 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6211 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 6212 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 6213 | null /* workSource */); |
| 6214 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | // Append the returned status code to the end of the response payload. |
| 6217 | String s = Integer.toHexString( |
| 6218 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6219 | if (response.payload != null) { |
| 6220 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6221 | } |
| 6222 | return s; |
| 6223 | } finally { |
| 6224 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 6225 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6229 | 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] | 6230 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6231 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6232 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6233 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6234 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6235 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "iccExchangeSimIO"); |
| 6236 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6237 | final long identity = Binder.clearCallingIdentity(); |
| 6238 | try { |
| 6239 | if (DBG) { |
| 6240 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 6241 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 6242 | } |
| 6243 | |
| 6244 | IccIoResult response = |
| 6245 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 6246 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 6247 | subId); |
| 6248 | |
| 6249 | if (DBG) { |
| 6250 | log("Exchange SIM_IO [R]" + response); |
| 6251 | } |
| 6252 | |
| 6253 | byte[] result = null; |
| 6254 | int length = 2; |
| 6255 | if (response.payload != null) { |
| 6256 | length = 2 + response.payload.length; |
| 6257 | result = new byte[length]; |
| 6258 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 6259 | } else { |
| 6260 | result = new byte[length]; |
| 6261 | } |
| 6262 | |
| 6263 | result[length - 1] = (byte) response.sw2; |
| 6264 | result[length - 2] = (byte) response.sw1; |
| 6265 | return result; |
| 6266 | } finally { |
| 6267 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6268 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6269 | } |
| 6270 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6271 | /** |
| 6272 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 6273 | * on a particular subscription |
| 6274 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6275 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 6276 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6277 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6278 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 6279 | return null; |
| 6280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6282 | enforceTelephonyFeatureWithException(callingPackage, |
| 6283 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getForbiddenPlmns"); |
| 6284 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6285 | final long identity = Binder.clearCallingIdentity(); |
| 6286 | try { |
| 6287 | if (appType != TelephonyManager.APPTYPE_USIM |
| 6288 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 6289 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6290 | return null; |
| 6291 | } |
| 6292 | Object response = sendRequest( |
| 6293 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 6294 | if (response instanceof String[]) { |
| 6295 | return (String[]) response; |
| 6296 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6297 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6299 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6300 | } finally { |
| 6301 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6302 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 6303 | } |
| 6304 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6305 | /** |
| 6306 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 6307 | * subscription. |
| 6308 | * |
| 6309 | * @param subId the id of the subscription. |
| 6310 | * @param appType the uicc app type, must be USIM or SIM. |
| 6311 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 6312 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6313 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6314 | * @return number of fplmns that is successfully written to the SIM. |
| 6315 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6316 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 6317 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 6318 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6319 | mApp, subId, "setForbiddenPlmns"); |
| 6320 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6321 | enforceTelephonyFeatureWithException(callingPackage, |
| 6322 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setForbiddenPlmns"); |
| 6323 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 6324 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 6325 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 6326 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 6327 | } |
| 6328 | if (fplmns == null) { |
| 6329 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 6330 | } |
| 6331 | for (String fplmn : fplmns) { |
| 6332 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 6333 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 6334 | } |
| 6335 | } |
| 6336 | final long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
| 6338 | Object response = sendRequest( |
| 6339 | CMD_SET_FORBIDDEN_PLMNS, |
| 6340 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 6341 | subId); |
| 6342 | return (int) response; |
| 6343 | } finally { |
| 6344 | Binder.restoreCallingIdentity(identity); |
| 6345 | } |
| 6346 | } |
| 6347 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 6348 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6349 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6351 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6352 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6353 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6354 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "sendEnvelopeWithStatus"); |
| 6355 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 | final long identity = Binder.clearCallingIdentity(); |
| 6357 | try { |
| 6358 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 6359 | if (response.payload == null) { |
| 6360 | return ""; |
| 6361 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6363 | // Append the returned status code to the end of the response payload. |
| 6364 | String s = Integer.toHexString( |
| 6365 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 6366 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 6367 | return s; |
| 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
| 6370 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 6371 | } |
| 6372 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6373 | /** |
| 6374 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6375 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6376 | * |
| 6377 | * @param itemID the ID of the item to read |
| 6378 | * @return the NV item as a String, or null on error. |
| 6379 | */ |
| 6380 | @Override |
| 6381 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6382 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6383 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6384 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6385 | |
| 6386 | final long identity = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6389 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 6391 | return value; |
| 6392 | } finally { |
| 6393 | Binder.restoreCallingIdentity(identity); |
| 6394 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | /** |
| 6398 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 6399 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 6400 | * |
| 6401 | * @param itemID the ID of the item to read |
| 6402 | * @param itemValue the value to write, as a String |
| 6403 | * @return true on success; false on any failure |
| 6404 | */ |
| 6405 | @Override |
| 6406 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6407 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6409 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | |
| 6411 | final long identity = Binder.clearCallingIdentity(); |
| 6412 | try { |
| 6413 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 6414 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6415 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6416 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 6417 | return success; |
| 6418 | } finally { |
| 6419 | Binder.restoreCallingIdentity(identity); |
| 6420 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6421 | } |
| 6422 | |
| 6423 | /** |
| 6424 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 6425 | * Used for device configuration by some CDMA operators. |
| 6426 | * |
| 6427 | * @param preferredRoamingList byte array containing the new PRL |
| 6428 | * @return true on success; false on any failure |
| 6429 | */ |
| 6430 | @Override |
| 6431 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6432 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6433 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6434 | |
| 6435 | final long identity = Binder.clearCallingIdentity(); |
| 6436 | try { |
| 6437 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 6438 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 6439 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 6440 | return success; |
| 6441 | } finally { |
| 6442 | Binder.restoreCallingIdentity(identity); |
| 6443 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6447 | * 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] | 6448 | * Used for device configuration by some CDMA operators. |
| 6449 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6450 | * @param slotIndex - device slot. |
| 6451 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6452 | * @return true on success; false on any failure |
| 6453 | */ |
| 6454 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6455 | public boolean resetModemConfig(int slotIndex) { |
| 6456 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6457 | if (phone != null) { |
| 6458 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6459 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6460 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6461 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6462 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "resetModemConfig"); |
| 6463 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6464 | final long identity = Binder.clearCallingIdentity(); |
| 6465 | try { |
| 6466 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 6467 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 6468 | return success; |
| 6469 | } finally { |
| 6470 | Binder.restoreCallingIdentity(identity); |
| 6471 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6473 | return false; |
| 6474 | } |
| 6475 | |
| 6476 | /** |
| 6477 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6478 | * |
| 6479 | * @param slotIndex - device slot. |
| 6480 | * |
| 6481 | * @return true on success; false on any failure |
| 6482 | */ |
| 6483 | @Override |
| 6484 | public boolean rebootModem(int slotIndex) { |
| 6485 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6486 | if (phone != null) { |
| 6487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6488 | mApp, phone.getSubId(), "rebootModem"); |
| 6489 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6491 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "rebootModem"); |
| 6492 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 6493 | final long identity = Binder.clearCallingIdentity(); |
| 6494 | try { |
| 6495 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6496 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6497 | return success; |
| 6498 | } finally { |
| 6499 | Binder.restoreCallingIdentity(identity); |
| 6500 | } |
| 6501 | } |
| 6502 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6503 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6504 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6505 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6506 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6507 | * {@link #disableIms(int)}. |
| 6508 | * @param slotIndex device slot. |
| 6509 | */ |
| 6510 | public void resetIms(int slotIndex) { |
| 6511 | enforceModifyPermission(); |
| 6512 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6513 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6514 | PackageManager.FEATURE_TELEPHONY_IMS, "resetIms"); |
| 6515 | |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6516 | final long identity = Binder.clearCallingIdentity(); |
| 6517 | try { |
| 6518 | if (mImsResolver == null) { |
| 6519 | // may happen if the does not support IMS. |
| 6520 | return; |
| 6521 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6522 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6523 | } finally { |
| 6524 | Binder.restoreCallingIdentity(identity); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6529 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6530 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6531 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6532 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6533 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6534 | |
| 6535 | final long identity = Binder.clearCallingIdentity(); |
| 6536 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6537 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6538 | // may happen if the device does not support IMS. |
| 6539 | return; |
| 6540 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6541 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6542 | } finally { |
| 6543 | Binder.restoreCallingIdentity(identity); |
| 6544 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6545 | } |
| 6546 | |
| 6547 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6548 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6549 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6550 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6551 | public void disableIms(int slotId) { |
| 6552 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6553 | |
| 6554 | final long identity = Binder.clearCallingIdentity(); |
| 6555 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6556 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6557 | // may happen if the device does not support IMS. |
| 6558 | return; |
| 6559 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6560 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6564 | } |
| 6565 | |
| 6566 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6567 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6568 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6569 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6570 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6571 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6572 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6573 | |
| 6574 | final long identity = Binder.clearCallingIdentity(); |
| 6575 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6576 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6577 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6578 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6579 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6580 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6581 | } finally { |
| 6582 | Binder.restoreCallingIdentity(identity); |
| 6583 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6584 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6585 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6586 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6587 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6588 | @Override |
| 6589 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6590 | enforceModifyPermission(); |
| 6591 | |
| 6592 | final long identity = Binder.clearCallingIdentity(); |
| 6593 | try { |
| 6594 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6595 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6596 | } finally { |
| 6597 | Binder.restoreCallingIdentity(identity); |
| 6598 | } |
| 6599 | } |
| 6600 | |
| 6601 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6602 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6603 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6604 | */ |
| 6605 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6606 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | |
| 6608 | final long identity = Binder.clearCallingIdentity(); |
| 6609 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6610 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6611 | // may happen if the device does not support IMS. |
| 6612 | return null; |
| 6613 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6614 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6615 | } finally { |
| 6616 | Binder.restoreCallingIdentity(identity); |
| 6617 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6618 | } |
| 6619 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6620 | /** |
| 6621 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6622 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6623 | */ |
| 6624 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6625 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6626 | |
| 6627 | final long identity = Binder.clearCallingIdentity(); |
| 6628 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6629 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6630 | // may happen if the device does not support IMS. |
| 6631 | return null; |
| 6632 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6633 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6634 | } finally { |
| 6635 | Binder.restoreCallingIdentity(identity); |
| 6636 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6637 | } |
| 6638 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6639 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6640 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6641 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6642 | * @param slotIndex the slot ID that the ImsService should bind for. |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame^] | 6643 | * @param userId the user ID that the ImsService should bind for or {@link UserHandle#USER_NULL} |
| 6644 | * if there is no preference. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6645 | * @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] | 6646 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6647 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6648 | * @param packageName The name of the package that the current configuration will be replaced |
| 6649 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6650 | * @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] | 6651 | */ |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame^] | 6652 | public boolean setBoundImsServiceOverride(int slotIndex, int userId, boolean isCarrierService, |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6653 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6654 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6656 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6660 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6661 | // may happen if the device does not support IMS. |
| 6662 | return false; |
| 6663 | } |
Brad Ebinger | 555ddec | 2024-11-04 13:46:31 -0800 | [diff] [blame^] | 6664 | return mImsResolver.overrideImsServiceConfiguration(packageName, slotIndex, userId, |
| 6665 | isCarrierService, featureTypes); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6666 | } finally { |
| 6667 | Binder.restoreCallingIdentity(identity); |
| 6668 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6672 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6673 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6674 | * |
| 6675 | * This should only be used for testing. |
| 6676 | * |
| 6677 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6678 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6679 | */ |
| 6680 | @Override |
| 6681 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6682 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6683 | "clearCarrierImsServiceOverride"); |
| 6684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6685 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6686 | |
| 6687 | final long identity = Binder.clearCallingIdentity(); |
| 6688 | try { |
| 6689 | if (mImsResolver == null) { |
| 6690 | // may happen if the device does not support IMS. |
| 6691 | return false; |
| 6692 | } |
| 6693 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6694 | } finally { |
| 6695 | Binder.restoreCallingIdentity(identity); |
| 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6700 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6701 | * |
| 6702 | * @param slotId The slot that the ImsService is associated with. |
| 6703 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6704 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6705 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6706 | * @return the package name of the ImsService configuration. |
| 6707 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6708 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6709 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6710 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6711 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6712 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6713 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | final long identity = Binder.clearCallingIdentity(); |
| 6715 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6716 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6717 | // may happen if the device does not support IMS. |
| 6718 | return ""; |
| 6719 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6720 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6721 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6722 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | } finally { |
| 6724 | Binder.restoreCallingIdentity(identity); |
| 6725 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6728 | /** |
| 6729 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6730 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6731 | * @param callback A callback with an integer containing the |
| 6732 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6733 | */ |
| 6734 | @Override |
| 6735 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6736 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6737 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6738 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6739 | "IMS not available on device."); |
| 6740 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6741 | final long token = Binder.clearCallingIdentity(); |
| 6742 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6743 | int slotId = getSlotIndex(subId); |
| 6744 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6745 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6746 | + subId + "'"); |
| 6747 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6748 | } |
| 6749 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6750 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6751 | try { |
| 6752 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6753 | } catch (RemoteException e) { |
| 6754 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6755 | + "Ignore"); |
| 6756 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6757 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6758 | } catch (ImsException e) { |
| 6759 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(token); |
| 6762 | } |
| 6763 | } |
| 6764 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6765 | /** |
| 6766 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6767 | */ |
| 6768 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6769 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | |
| 6771 | final long identity = Binder.clearCallingIdentity(); |
| 6772 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6773 | // NOTE: Before S, this method only set the default phone. |
| 6774 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6775 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6776 | phone.setImsRegistrationState(registered); |
| 6777 | } |
| 6778 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | } finally { |
| 6780 | Binder.restoreCallingIdentity(identity); |
| 6781 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6785 | * Set the network selection mode to automatic. |
| 6786 | * |
| 6787 | */ |
| 6788 | @Override |
| 6789 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6791 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6792 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6793 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6794 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeAutomatic"); |
| 6795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6796 | final long identity = Binder.clearCallingIdentity(); |
| 6797 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6798 | if (!isActiveSubscription(subId)) { |
| 6799 | return; |
| 6800 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6801 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6802 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
Nathan Harold | dc3bcec | 2024-05-16 14:06:40 -0700 | [diff] [blame] | 6803 | BLOCKING_REQUEST_DEFAULT_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6804 | } finally { |
| 6805 | Binder.restoreCallingIdentity(identity); |
| 6806 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6807 | } |
| 6808 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6809 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6810 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6811 | * |
| 6812 | * @param subId the id of the subscription. |
| 6813 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6814 | * the operator to attach to. |
| 6815 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6816 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6817 | * normal network selection next time. |
| 6818 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6819 | */ |
| 6820 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6821 | public boolean setNetworkSelectionModeManual( |
| 6822 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6824 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6825 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6826 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6827 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setNetworkSelectionModeManual"); |
| 6828 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6829 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6830 | if (!isActiveSubscription(subId)) { |
| 6831 | return false; |
| 6832 | } |
| 6833 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6835 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6837 | if (DBG) { |
| 6838 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6839 | + " operator: " + operatorInfo); |
| 6840 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6842 | } finally { |
| 6843 | Binder.restoreCallingIdentity(identity); |
| 6844 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6845 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6846 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6847 | * Get the manual network selection |
| 6848 | * |
| 6849 | * @param subId the id of the subscription. |
| 6850 | * |
| 6851 | * @return the previously saved user selected PLMN |
| 6852 | */ |
| 6853 | @Override |
| 6854 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6855 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6856 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6857 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6858 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6859 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6860 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getManualNetworkSelectionPlmn"); |
| 6861 | |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6862 | final long identity = Binder.clearCallingIdentity(); |
| 6863 | try { |
| 6864 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6865 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6866 | } |
| 6867 | |
| 6868 | final Phone phone = getPhone(subId); |
| 6869 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6870 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6871 | } |
| 6872 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6873 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6874 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6875 | } finally { |
| 6876 | Binder.restoreCallingIdentity(identity); |
| 6877 | } |
| 6878 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6879 | |
| 6880 | /** |
| 6881 | * Scans for available networks. |
| 6882 | */ |
| 6883 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6884 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6885 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6887 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6888 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6889 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6890 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6891 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6892 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6893 | .setCallingPid(Binder.getCallingPid()) |
| 6894 | .setCallingUid(Binder.getCallingUid()) |
| 6895 | .setMethod("getCellNetworkScanResults") |
| 6896 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6897 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6898 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6899 | .build()); |
| 6900 | switch (locationResult) { |
| 6901 | case DENIED_HARD: |
| 6902 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6903 | case DENIED_SOFT: |
| 6904 | return null; |
| 6905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6906 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6907 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6908 | try { |
| 6909 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6910 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6911 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(identity); |
| 6914 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6918 | * Get the call forwarding info, given the call forwarding reason. |
| 6919 | */ |
| 6920 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6921 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6922 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6923 | enforceReadPrivilegedPermission("getCallForwarding"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6924 | |
| 6925 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6926 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallForwarding"); |
| 6927 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6928 | long identity = Binder.clearCallingIdentity(); |
| 6929 | try { |
| 6930 | if (DBG) { |
| 6931 | log("getCallForwarding: subId " + subId |
| 6932 | + " callForwardingReason" + callForwardingReason); |
| 6933 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6934 | |
| 6935 | Phone phone = getPhone(subId); |
| 6936 | if (phone == null) { |
| 6937 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6938 | callback.onError( |
| 6939 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6940 | } catch (RemoteException e) { |
| 6941 | // ignore |
| 6942 | } |
| 6943 | return; |
| 6944 | } |
| 6945 | |
| 6946 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6947 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6948 | @Override |
| 6949 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6950 | try { |
| 6951 | callback.onCallForwardingInfoAvailable(info); |
| 6952 | } catch (RemoteException e) { |
| 6953 | // ignore |
| 6954 | } |
| 6955 | } |
| 6956 | |
| 6957 | @Override |
| 6958 | public void onError(int error) { |
| 6959 | try { |
| 6960 | callback.onError(error); |
| 6961 | } catch (RemoteException e) { |
| 6962 | // ignore |
| 6963 | } |
| 6964 | } |
| 6965 | }); |
| 6966 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6967 | } finally { |
| 6968 | Binder.restoreCallingIdentity(identity); |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | /** |
| 6973 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6974 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6975 | */ |
| 6976 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6977 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6978 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6979 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 6980 | |
| 6981 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 6982 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallForwarding"); |
| 6983 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6984 | long identity = Binder.clearCallingIdentity(); |
| 6985 | try { |
| 6986 | if (DBG) { |
| 6987 | log("setCallForwarding: subId " + subId |
| 6988 | + " callForwardingInfo" + callForwardingInfo); |
| 6989 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6990 | |
| 6991 | Phone phone = getPhone(subId); |
| 6992 | if (phone == null) { |
| 6993 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6994 | callback.accept( |
| 6995 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6996 | } catch (RemoteException e) { |
| 6997 | // ignore |
| 6998 | } |
| 6999 | return; |
| 7000 | } |
| 7001 | |
| 7002 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 7003 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7004 | |
| 7005 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7006 | } finally { |
| 7007 | Binder.restoreCallingIdentity(identity); |
| 7008 | } |
| 7009 | } |
| 7010 | |
| 7011 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7012 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7013 | */ |
| 7014 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7015 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7016 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7017 | |
| 7018 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7019 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallWaitingStatus"); |
| 7020 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7021 | long identity = Binder.clearCallingIdentity(); |
| 7022 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7023 | Phone phone = getPhone(subId); |
| 7024 | if (phone == null) { |
| 7025 | try { |
| 7026 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7027 | } catch (RemoteException e) { |
| 7028 | // ignore |
| 7029 | } |
| 7030 | return; |
| 7031 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7032 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7033 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7034 | boolean requireUssd = c.getBoolean( |
| 7035 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7036 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7037 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7038 | if (requireUssd) { |
| 7039 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7040 | getSubscriptionCarrierId(subId)); |
| 7041 | String newUssdCommand = ""; |
| 7042 | try { |
| 7043 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7044 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7045 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 7046 | } catch (NullPointerException e) { |
| 7047 | loge("Failed to generate USSD number" + e); |
| 7048 | } |
| 7049 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7050 | mMainThreadHandler, callback, carrierXmlParser, |
| 7051 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 7052 | final String ussdCommand = newUssdCommand; |
| 7053 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7054 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7055 | }); |
| 7056 | } else { |
| 7057 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 7058 | callback::accept); |
| 7059 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 7060 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
| 7063 | } |
| 7064 | } |
| 7065 | |
| 7066 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7067 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7068 | */ |
| 7069 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7070 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7071 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7072 | |
| 7073 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7074 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallWaitingStatus"); |
| 7075 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7076 | long identity = Binder.clearCallingIdentity(); |
| 7077 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7078 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 7079 | |
| 7080 | Phone phone = getPhone(subId); |
| 7081 | if (phone == null) { |
| 7082 | try { |
| 7083 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 7084 | } catch (RemoteException e) { |
| 7085 | // ignore |
| 7086 | } |
| 7087 | return; |
| 7088 | } |
| 7089 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7090 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 7091 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 7092 | boolean requireUssd = c.getBoolean( |
| 7093 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 7094 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7095 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 7096 | if (requireUssd) { |
| 7097 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 7098 | getSubscriptionCarrierId(subId)); |
| 7099 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 7100 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 7101 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 7102 | String newUssdCommand = ""; |
| 7103 | try { |
| 7104 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7105 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 7106 | .makeCommand(ssAction, null); |
| 7107 | } catch (NullPointerException e) { |
| 7108 | loge("Failed to generate USSD number" + e); |
| 7109 | } |
| 7110 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 7111 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 7112 | final String ussdCommand = newUssdCommand; |
| 7113 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7114 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 7115 | }); |
| 7116 | } else { |
| 7117 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 7118 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 7119 | |
| 7120 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 7121 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 7122 | } finally { |
| 7123 | Binder.restoreCallingIdentity(identity); |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7128 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7129 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7130 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7131 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 7132 | * location related information which will be sent if the caller already possess |
| 7133 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7134 | * @param request contains the radio access networks with bands/channels to scan |
| 7135 | * @param messenger callback messenger for scan results or errors |
| 7136 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7137 | * @return the id of the requested scan which can be used to stop the scan. |
| 7138 | */ |
| 7139 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7140 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 7141 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7142 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7144 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7145 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7146 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 7147 | if (!renounceFineLocationAccess) { |
| 7148 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7149 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7150 | .setCallingPackage(callingPackage) |
| 7151 | .setCallingFeatureId(callingFeatureId) |
| 7152 | .setCallingPid(Binder.getCallingPid()) |
| 7153 | .setCallingUid(Binder.getCallingUid()) |
| 7154 | .setMethod("requestNetworkScan") |
| 7155 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7156 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7157 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7158 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7159 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7160 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7161 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 7162 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7163 | if (e != null) { |
| 7164 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 7165 | throw e; |
| 7166 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 7167 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7168 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 7169 | } |
| 7170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7172 | |
| 7173 | enforceTelephonyFeatureWithException(callingPackage, |
| 7174 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "requestNetworkScan"); |
| 7175 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7176 | int callingUid = Binder.getCallingUid(); |
| 7177 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
| 7180 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 7181 | renounceFineLocationAccess, request, messenger, binder, |
| 7182 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7183 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7187 | } |
| 7188 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7189 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 7190 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 7191 | boolean hasCarrierPriv; |
| 7192 | final long identity = Binder.clearCallingIdentity(); |
| 7193 | try { |
| 7194 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 7195 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 7196 | } finally { |
| 7197 | Binder.restoreCallingIdentity(identity); |
| 7198 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7199 | boolean hasNetworkScanPermission = |
| 7200 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7201 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 7202 | |
| 7203 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 7204 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 7205 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7206 | } |
| 7207 | |
| 7208 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 7209 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7210 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 7211 | return new SecurityException("Specific channels must not be" |
| 7212 | + " scanned without location access."); |
| 7213 | } |
| 7214 | } |
| 7215 | } |
| 7216 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 7217 | return null; |
| 7218 | } |
| 7219 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7220 | /** |
| 7221 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 7222 | * |
| 7223 | * @param subId id of the subscription |
| 7224 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7225 | */ |
| 7226 | @Override |
| 7227 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7229 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7231 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7232 | final long identity = Binder.clearCallingIdentity(); |
| 7233 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 7234 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | } finally { |
| 7236 | Binder.restoreCallingIdentity(identity); |
| 7237 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 7238 | } |
| 7239 | |
| 7240 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7241 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7242 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7243 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 7244 | */ |
| 7245 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7246 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 7247 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7248 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7249 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7251 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7252 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getAllowedNetworkTypesBitmask"); |
| 7253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | final long identity = Binder.clearCallingIdentity(); |
| 7255 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7256 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 7257 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 7258 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 7259 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 7260 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7261 | } finally { |
| 7262 | Binder.restoreCallingIdentity(identity); |
| 7263 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 7264 | } |
| 7265 | |
| 7266 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7267 | * Get the allowed network types for certain reason. |
| 7268 | * |
| 7269 | * @param subId the id of the subscription. |
| 7270 | * @param reason the reason the allowed network type change is taking place |
| 7271 | * @return the allowed network types. |
| 7272 | */ |
| 7273 | @Override |
| 7274 | public long getAllowedNetworkTypesForReason(int subId, |
| 7275 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7276 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7277 | mApp, subId, "getAllowedNetworkTypesForReason"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7278 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7279 | if (!mApp.getResources().getBoolean( |
| 7280 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7281 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7282 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 7283 | "getAllowedNetworkTypesForReason"); |
| 7284 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7285 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7286 | final long identity = Binder.clearCallingIdentity(); |
| 7287 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 7288 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7289 | } finally { |
| 7290 | Binder.restoreCallingIdentity(identity); |
| 7291 | } |
| 7292 | } |
| 7293 | |
| 7294 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7295 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 7296 | * @param subId subscription id of the sim card |
| 7297 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 7298 | * This can be passed following states |
| 7299 | * <ol> |
| 7300 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 7301 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 7302 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 7303 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 7304 | * </ol> |
| 7305 | * @return operation result. |
| 7306 | */ |
| 7307 | @Override |
| 7308 | public int setNrDualConnectivityState(int subId, |
| 7309 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 7310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7311 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7312 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7313 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7314 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 7315 | } |
| 7316 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7317 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7318 | final long identity = Binder.clearCallingIdentity(); |
| 7319 | try { |
| 7320 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 7321 | nrDualConnectivityState, subId, |
| 7322 | workSource); |
| 7323 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 7324 | return result; |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | /** |
| 7331 | * Is E-UTRA-NR Dual Connectivity enabled |
| 7332 | * @return true if dual connectivity is enabled else false |
| 7333 | */ |
| 7334 | @Override |
| 7335 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 7336 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7337 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7338 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 7339 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 7340 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 7341 | return false; |
| 7342 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 7343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
| 7346 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 7347 | null, subId, workSource); |
| 7348 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 7349 | return isEnabled; |
| 7350 | } finally { |
| 7351 | Binder.restoreCallingIdentity(identity); |
| 7352 | } |
| 7353 | } |
| 7354 | |
| 7355 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7356 | * Set the allowed network types of the device and |
| 7357 | * provide the reason triggering the allowed network change. |
| 7358 | * |
| 7359 | * @param subId the id of the subscription. |
| 7360 | * @param reason the reason the allowed network type change is taking place |
| 7361 | * @param allowedNetworkTypes the allowed network types. |
| 7362 | * @return true on success; false on any failure. |
| 7363 | */ |
| 7364 | @Override |
| 7365 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7366 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 7367 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7369 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7370 | // If the caller only has carrier privileges, then they should not be able to override |
| 7371 | // any network types which were set for security reasons. |
| 7372 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 7373 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7374 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7375 | throw new SecurityException( |
| 7376 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 7377 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 7378 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7379 | |
| 7380 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7381 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setAllowedNetworkTypesForReason"); |
| 7382 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7383 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7384 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 7385 | return false; |
| 7386 | } |
| 7387 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7388 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7389 | return false; |
| 7390 | } |
| 7391 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7392 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 7393 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7394 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7395 | Phone phone = getPhone(subId); |
| 7396 | if (phone == null) { |
| 7397 | return false; |
| 7398 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7399 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 7400 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 7401 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7402 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7403 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7404 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7407 | Boolean success = (Boolean) sendRequest( |
| 7408 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 7409 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 7410 | |
| 7411 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 7412 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
| 7415 | } |
| 7416 | } |
| 7417 | |
| 7418 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7419 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7420 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7421 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 7422 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7423 | * @hide |
| 7424 | */ |
| 7425 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 7426 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7427 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7428 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 7429 | if (!mApp.getResources().getBoolean( |
| 7430 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7431 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7432 | PackageManager.FEATURE_TELEPHONY_DATA, "isTetheringApnRequiredForSubscriber"); |
| 7433 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7434 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7435 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7436 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 7438 | if (phone != null) { |
| 7439 | return phone.hasMatchedTetherApnSetting(); |
| 7440 | } else { |
| 7441 | return false; |
| 7442 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7445 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 7446 | } |
| 7447 | |
| 7448 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7449 | * Get the user enabled state of Mobile Data. |
| 7450 | * |
| 7451 | * TODO: remove and use isUserDataEnabled. |
| 7452 | * This can't be removed now because some vendor codes |
| 7453 | * calls through ITelephony directly while they should |
| 7454 | * use TelephonyManager. |
| 7455 | * |
| 7456 | * @return true on enabled |
| 7457 | */ |
| 7458 | @Override |
| 7459 | public boolean getDataEnabled(int subId) { |
| 7460 | return isUserDataEnabled(subId); |
| 7461 | } |
| 7462 | |
| 7463 | /** |
| 7464 | * Get whether mobile data is enabled per user setting. |
| 7465 | * |
| 7466 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 7467 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7468 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7469 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 7470 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7471 | * |
| 7472 | * @return {@code true} if data is enabled else {@code false} |
| 7473 | */ |
| 7474 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7475 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7476 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7477 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7478 | try { |
| 7479 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7480 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7481 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7482 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 7483 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7484 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7486 | mApp, subId, functionName); |
| 7487 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 7488 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7489 | |
| 7490 | final long identity = Binder.clearCallingIdentity(); |
| 7491 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7492 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 7494 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7495 | if (phone != null) { |
| 7496 | boolean retVal = phone.isUserDataEnabled(); |
| 7497 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 7498 | return retVal; |
| 7499 | } else { |
| 7500 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7501 | return false; |
| 7502 | } |
| 7503 | } finally { |
| 7504 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7505 | } |
| 7506 | } |
| 7507 | |
| 7508 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7509 | * Checks if the device is capable of mobile data by considering whether whether the |
| 7510 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 7511 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 7512 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 7513 | * @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] | 7514 | */ |
| 7515 | @Override |
| 7516 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7517 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7518 | try { |
| 7519 | try { |
| 7520 | mApp.enforceCallingOrSelfPermission( |
| 7521 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7522 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7523 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7524 | try { |
| 7525 | mApp.enforceCallingOrSelfPermission( |
| 7526 | android.Manifest.permission.READ_PHONE_STATE, |
| 7527 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7528 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7529 | mApp.enforceCallingOrSelfPermission( |
| 7530 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 7531 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7532 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7533 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7534 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7535 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7537 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7538 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabled"); |
| 7539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | final long identity = Binder.clearCallingIdentity(); |
| 7541 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7542 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7544 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7545 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7546 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | return retVal; |
| 7548 | } else { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7549 | if (DBG) { |
| 7550 | loge("isDataEnabled: no phone or no DataSettingsManager subId=" |
| 7551 | + subId + " retVal=false"); |
| 7552 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7553 | return false; |
| 7554 | } |
| 7555 | } finally { |
| 7556 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7557 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7558 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7559 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7560 | /** |
| 7561 | * Check if data is enabled for a specific reason |
| 7562 | * @param subId Subscription index |
| 7563 | * @param reason the reason the data enable change is taking place |
| 7564 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7565 | */ |
| 7566 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7567 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7568 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7569 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7570 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7571 | try { |
| 7572 | mApp.enforceCallingOrSelfPermission( |
| 7573 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7574 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7575 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7576 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7577 | functionName); |
| 7578 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7579 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7580 | try { |
| 7581 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7582 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7583 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7585 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7586 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7587 | } |
| 7588 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7589 | if (!mApp.getResources().getBoolean( |
| 7590 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7591 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7592 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForReason"); |
| 7593 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7594 | |
| 7595 | final long identity = Binder.clearCallingIdentity(); |
| 7596 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7597 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7598 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7599 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7600 | + " reason=" + reason); |
| 7601 | } |
| 7602 | Phone phone = PhoneFactory.getPhone(phoneId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7603 | if (phone != null && phone.getDataSettingsManager() != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7604 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7605 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7606 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7607 | return retVal; |
| 7608 | } else { |
| 7609 | if (DBG) { |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 7610 | loge("isDataEnabledForReason: no phone or no DataSettingsManager subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7611 | + subId + " retVal=false"); |
| 7612 | } |
| 7613 | return false; |
| 7614 | } |
| 7615 | } finally { |
| 7616 | Binder.restoreCallingIdentity(identity); |
| 7617 | } |
| 7618 | } |
| 7619 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7620 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7621 | public int getCarrierPrivilegeStatus(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7622 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7623 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getCarrierPrivilegeStatus"); |
| 7624 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7625 | // No permission needed; this only lets the caller inspect their own status. |
| 7626 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7627 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7628 | |
| 7629 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7630 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7631 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7632 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7633 | if (!mApp.getResources().getBoolean( |
| 7634 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7635 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7636 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7637 | "getCarrierPrivilegeStatusForUid"); |
| 7638 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7639 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7640 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7641 | } |
| 7642 | |
| 7643 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7644 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7645 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7646 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7647 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7648 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7649 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7650 | if (cpt == null) { |
| 7651 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7652 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7653 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7654 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7655 | } |
| 7656 | |
| 7657 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7658 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7659 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7660 | |
| 7661 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7662 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "checkCarrierPrivilegesForPackage"); |
| 7663 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7664 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7665 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7666 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7667 | Phone phone = getPhone(subId); |
| 7668 | if (phone == null) { |
| 7669 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7670 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7671 | } |
| 7672 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7673 | if (cpt == null) { |
| 7674 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7675 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7676 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7677 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7678 | } |
| 7679 | |
| 7680 | @Override |
| 7681 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7682 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7683 | |
Tomasz Wasilczyk | 406b9b3 | 2024-07-10 15:45:21 -0700 | [diff] [blame] | 7684 | if (!mApp.getResources().getBoolean( |
| 7685 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7686 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7687 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7688 | "checkCarrierPrivilegesForPackageAnyPhone"); |
| 7689 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7690 | |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7691 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7692 | } |
| 7693 | |
| 7694 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7695 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7696 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7697 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7698 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7699 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7700 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7701 | if (phone == null) { |
| 7702 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7703 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7704 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7705 | if (cpt == null) { |
| 7706 | continue; |
| 7707 | } |
| 7708 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7709 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7710 | break; |
| 7711 | } |
| 7712 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7713 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7714 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7715 | |
| 7716 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7717 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7718 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7719 | |
| 7720 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7721 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7722 | "getCarrierPackageNamesForIntentAndPhone"); |
| 7723 | |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7724 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7725 | if (phone == null) { |
| 7726 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7727 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7728 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7729 | if (cpt == null) { |
| 7730 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7731 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7732 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7733 | } |
| 7734 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7735 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7736 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7737 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Yan Yan | 965c84f | 2024-09-24 18:14:17 -0700 | [diff] [blame] | 7738 | |
| 7739 | enforceTelephonyFeatureWithException( |
| 7740 | getCurrentPackageName(), |
| 7741 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7742 | "getPackagesWithCarrierPrivileges"); |
| 7743 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7744 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7745 | if (phone == null) { |
| 7746 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7747 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7748 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7749 | if (cpt == null) { |
| 7750 | return Collections.emptyList(); |
| 7751 | } |
| 7752 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7753 | } |
| 7754 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7755 | @Override |
| 7756 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7757 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7758 | |
| 7759 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7760 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7761 | "getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7762 | |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7763 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7764 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7765 | try { |
| 7766 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7767 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7768 | } |
| 7769 | } finally { |
| 7770 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7771 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7772 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7775 | @Override |
| 7776 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7777 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7778 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 7779 | if (!mApp.getResources().getBoolean( |
| 7780 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7781 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7782 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7783 | "getCarrierServicePackageNameForLogicalSlot"); |
| 7784 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7785 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7786 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7787 | if (phone == null) { |
| 7788 | return null; |
| 7789 | } |
| 7790 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7791 | if (cpt == null) { |
| 7792 | return null; |
| 7793 | } |
| 7794 | return cpt.getCarrierServicePackageName(); |
| 7795 | } |
| 7796 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7797 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7798 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7799 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7800 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7801 | return null; |
| 7802 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7803 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7804 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7805 | return null; |
| 7806 | } |
| 7807 | return iccId; |
| 7808 | } |
| 7809 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7810 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7811 | public void setCallComposerStatus(int subId, int status) { |
| 7812 | enforceModifyPermission(); |
| 7813 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7814 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7815 | PackageManager.FEATURE_TELEPHONY_CALLING, "setCallComposerStatus"); |
| 7816 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7817 | final long identity = Binder.clearCallingIdentity(); |
| 7818 | try { |
| 7819 | Phone phone = getPhone(subId); |
| 7820 | if (phone != null) { |
| 7821 | Phone defaultPhone = phone.getImsPhone(); |
| 7822 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7823 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7824 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7825 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7826 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7827 | } |
| 7828 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7829 | } catch (ImsException e) { |
| 7830 | throw new ServiceSpecificException(e.getCode()); |
| 7831 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7832 | Binder.restoreCallingIdentity(identity); |
| 7833 | } |
| 7834 | } |
| 7835 | |
| 7836 | @Override |
| 7837 | public int getCallComposerStatus(int subId) { |
| 7838 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7839 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7840 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7841 | PackageManager.FEATURE_TELEPHONY_CALLING, "getCallComposerStatus"); |
| 7842 | |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7843 | final long identity = Binder.clearCallingIdentity(); |
| 7844 | try { |
| 7845 | Phone phone = getPhone(subId); |
| 7846 | if (phone != null) { |
| 7847 | Phone defaultPhone = phone.getImsPhone(); |
| 7848 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7849 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7850 | return imsPhone.getCallComposerStatus(); |
| 7851 | } |
| 7852 | } |
| 7853 | } finally { |
| 7854 | Binder.restoreCallingIdentity(identity); |
| 7855 | } |
| 7856 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7857 | } |
| 7858 | |
| 7859 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7860 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7861 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7862 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7863 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7864 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7865 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 7866 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 7867 | "setLine1NumberForDisplayForSubscriber"); |
| 7868 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7869 | final long identity = Binder.clearCallingIdentity(); |
| 7870 | try { |
| 7871 | final String iccId = getIccId(subId); |
| 7872 | final Phone phone = getPhone(subId); |
| 7873 | if (phone == null) { |
| 7874 | return false; |
| 7875 | } |
arunvoddu | b1365e6 | 2024-07-31 09:42:31 +0000 | [diff] [blame] | 7876 | if (!TextUtils.isEmpty(number) && number.length() > LINE1_NUMBER_MAX_LEN) { |
| 7877 | Rlog.e(LOG_TAG, "Number is too long"); |
| 7878 | return false; |
| 7879 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7880 | final String subscriberId = phone.getSubscriberId(); |
| 7881 | |
| 7882 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7883 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7884 | + subscriberId + " to " + number); |
| 7885 | } |
| 7886 | |
| 7887 | if (TextUtils.isEmpty(iccId)) { |
| 7888 | return false; |
| 7889 | } |
| 7890 | |
| 7891 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7892 | |
| 7893 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7894 | if (alphaTag == null) { |
| 7895 | editor.remove(alphaTagPrefKey); |
| 7896 | } else { |
| 7897 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7898 | } |
| 7899 | |
| 7900 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7901 | // track all merged IMSIs based on line number |
| 7902 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7903 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7904 | if (number == null) { |
| 7905 | editor.remove(numberPrefKey); |
| 7906 | editor.remove(subscriberPrefKey); |
| 7907 | } else { |
| 7908 | editor.putString(numberPrefKey, number); |
| 7909 | editor.putString(subscriberPrefKey, subscriberId); |
| 7910 | } |
| 7911 | |
| 7912 | editor.commit(); |
| 7913 | return true; |
| 7914 | } finally { |
| 7915 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7916 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7917 | } |
| 7918 | |
| 7919 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7920 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7921 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7922 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7923 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7924 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7925 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7926 | return null; |
| 7927 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7928 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 7929 | if (!mApp.getResources().getBoolean( |
| 7930 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 7931 | enforceTelephonyFeatureWithException(callingPackage, |
| 7932 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getLine1NumberForDisplay"); |
| 7933 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 7934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | final long identity = Binder.clearCallingIdentity(); |
| 7936 | try { |
| 7937 | String iccId = getIccId(subId); |
| 7938 | if (iccId != null) { |
| 7939 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7940 | if (DBG_MERGE) { |
| 7941 | log("getLine1NumberForDisplay returning " |
| 7942 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7943 | } |
| 7944 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7946 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7947 | return null; |
| 7948 | } finally { |
| 7949 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7950 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7951 | } |
| 7952 | |
| 7953 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7954 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7955 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7956 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7957 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7958 | return null; |
| 7959 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7960 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7961 | final long identity = Binder.clearCallingIdentity(); |
| 7962 | try { |
| 7963 | String iccId = getIccId(subId); |
| 7964 | if (iccId != null) { |
| 7965 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7966 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7967 | } |
| 7968 | return null; |
| 7969 | } finally { |
| 7970 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7971 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7972 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7973 | |
| 7974 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7975 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7976 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7977 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7978 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7980 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7981 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7982 | return null; |
| 7983 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7984 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7985 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7986 | // the process, where TelephonyManager was instantiated. |
| 7987 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7988 | final long identity = Binder.clearCallingIdentity(); |
| 7989 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7990 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7991 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7992 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7993 | |
| 7994 | // Figure out what subscribers are currently active |
| 7995 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7996 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7997 | // Only consider subs which match the current subId |
| 7998 | // This logic can be simplified. See b/131189269 for progress. |
| 7999 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8000 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 8001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8002 | |
| 8003 | // First pass, find a number override for an active subscriber |
| 8004 | String mergeNumber = null; |
| 8005 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 8006 | for (String key : prefs.keySet()) { |
| 8007 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 8008 | final String subscriberId = (String) prefs.get(key); |
| 8009 | if (activeSubscriberIds.contains(subscriberId)) { |
| 8010 | final String iccId = key.substring( |
| 8011 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 8012 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 8013 | mergeNumber = (String) prefs.get(numberKey); |
| 8014 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8015 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8016 | + " for active subscriber " + subscriberId); |
| 8017 | } |
| 8018 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 8019 | break; |
| 8020 | } |
| 8021 | } |
| 8022 | } |
| 8023 | } |
| 8024 | |
| 8025 | // Shortcut when no active merged subscribers |
| 8026 | if (TextUtils.isEmpty(mergeNumber)) { |
| 8027 | return null; |
| 8028 | } |
| 8029 | |
| 8030 | // Second pass, find all subscribers under that line override |
| 8031 | final ArraySet<String> result = new ArraySet<>(); |
| 8032 | for (String key : prefs.keySet()) { |
| 8033 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 8034 | final String number = (String) prefs.get(key); |
| 8035 | if (mergeNumber.equals(number)) { |
| 8036 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 8037 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 8038 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 8039 | if (!TextUtils.isEmpty(subscriberId)) { |
| 8040 | result.add(subscriberId); |
| 8041 | } |
| 8042 | } |
| 8043 | } |
| 8044 | } |
| 8045 | |
| 8046 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 8047 | Arrays.sort(resultArray); |
| 8048 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 8049 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8050 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 8051 | } |
| 8052 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 8053 | } finally { |
| 8054 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8055 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 8056 | } |
| 8057 | |
| 8058 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8059 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 8060 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8061 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8062 | enforceTelephonyFeatureWithException(callingPackage, |
| 8063 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getMergedImsisFromGroup"); |
| 8064 | |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8065 | final long identity = Binder.clearCallingIdentity(); |
| 8066 | try { |
| 8067 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 8068 | TelephonyManager.class); |
| 8069 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 8070 | if (subscriberId == null) { |
| 8071 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 8072 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8073 | + subId); |
| 8074 | } |
| 8075 | return null; |
| 8076 | } |
| 8077 | |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8078 | final SubscriptionInfo info = getSubscriptionManagerService() |
| 8079 | .getSubscriptionInfo(subId); |
| 8080 | ParcelUuid groupUuid = info.getGroupUuid(); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8081 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 8082 | if (groupUuid == null) { |
| 8083 | return new String[]{subscriberId}; |
| 8084 | } |
| 8085 | |
| 8086 | // Get all subscriberIds from the group. |
| 8087 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8088 | List<SubscriptionInfo> groupInfos = getSubscriptionManagerService() |
| 8089 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 8090 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 8091 | for (SubscriptionInfo subInfo : groupInfos) { |
| 8092 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 8093 | if (subscriberId != null) { |
| 8094 | mergedSubscriberIds.add(subscriberId); |
| 8095 | } |
| 8096 | } |
| 8097 | |
| 8098 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 8099 | } finally { |
| 8100 | Binder.restoreCallingIdentity(identity); |
| 8101 | |
| 8102 | } |
| 8103 | } |
| 8104 | |
| 8105 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8106 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8107 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8108 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8109 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8110 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8111 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setOperatorBrandOverride"); |
| 8112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | final long identity = Binder.clearCallingIdentity(); |
| 8114 | try { |
| 8115 | final Phone phone = getPhone(subId); |
| 8116 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 8117 | } finally { |
| 8118 | Binder.restoreCallingIdentity(identity); |
| 8119 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 8120 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 8121 | |
| 8122 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8123 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8124 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 8125 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 8126 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 8127 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8128 | |
| 8129 | final long identity = Binder.clearCallingIdentity(); |
| 8130 | try { |
| 8131 | final Phone phone = getPhone(subId); |
| 8132 | if (phone == null) { |
| 8133 | return false; |
| 8134 | } |
| 8135 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 8136 | cdmaNonRoamingList); |
| 8137 | } finally { |
| 8138 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 8139 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 8140 | } |
| 8141 | |
| 8142 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 8143 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8144 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8145 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8146 | if (phone == null) { |
| 8147 | return raf; |
| 8148 | } |
| 8149 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8150 | try { |
| 8151 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8152 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 8153 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 8154 | } catch (SecurityException e) { |
| 8155 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 8156 | throw e; |
| 8157 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 8158 | |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 8159 | if (!mApp.getResources().getBoolean( |
| 8160 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8161 | enforceTelephonyFeatureWithException(callingPackage, |
| 8162 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioAccessFamily"); |
| 8163 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8167 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8168 | } finally { |
| 8169 | Binder.restoreCallingIdentity(identity); |
| 8170 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 8171 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 8172 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8173 | |
| 8174 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8175 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 8176 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8177 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), |
| 8178 | "Invalid package:" + callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8179 | enforceTelephonyFeatureWithException(callingPackage, |
| 8180 | PackageManager.FEATURE_TELEPHONY_CALLING, "uploadCallComposerPicture"); |
| 8181 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8182 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
Rambo Wang | 7eb2696 | 2024-07-11 19:48:30 +0000 | [diff] [blame] | 8183 | List<String> dialerRoleHolders; |
Jack Yu | b6e8bad | 2024-09-01 19:56:34 -0700 | [diff] [blame] | 8184 | dialerRoleHolders = rm.getRoleHoldersAsUser(RoleManager.ROLE_DIALER, |
| 8185 | UserHandle.of(ActivityManager.getCurrentUser())); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8186 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 8187 | throw new SecurityException("App must be the dialer role holder to" |
| 8188 | + " upload a call composer pic"); |
| 8189 | } |
| 8190 | |
| 8191 | Executors.newSingleThreadExecutor().execute(() -> { |
| 8192 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 8193 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 8194 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 8195 | boolean readUntilEnd = false; |
| 8196 | int totalBytesRead = 0; |
| 8197 | byte[] buffer = new byte[16 * 1024]; |
| 8198 | while (true) { |
| 8199 | int numRead; |
| 8200 | try { |
| 8201 | numRead = input.read(buffer); |
| 8202 | } catch (IOException e) { |
| 8203 | try { |
| 8204 | fd.checkError(); |
| 8205 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 8206 | null); |
| 8207 | } catch (IOException e1) { |
| 8208 | // This means that the other side closed explicitly with an error. If this |
| 8209 | // happens, log and ignore. |
| 8210 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 8211 | } |
| 8212 | break; |
| 8213 | } |
| 8214 | if (numRead == -1) { |
| 8215 | readUntilEnd = true; |
| 8216 | break; |
| 8217 | } |
| 8218 | totalBytesRead += numRead; |
| 8219 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 8220 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 8221 | try { |
| 8222 | input.close(); |
| 8223 | } catch (IOException e) { |
| 8224 | // ignore |
| 8225 | } |
| 8226 | break; |
| 8227 | } |
| 8228 | output.write(buffer, 0, numRead); |
| 8229 | } |
| 8230 | // Generally, the remote end will close the file descriptors. The only case where we |
| 8231 | // close is above, where the picture size is too big. |
| 8232 | |
| 8233 | try { |
| 8234 | fd.checkError(); |
| 8235 | } catch (IOException e) { |
| 8236 | loge("Remote end for call composer closed with an error: " + e); |
| 8237 | return; |
| 8238 | } |
| 8239 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8240 | if (!readUntilEnd) { |
| 8241 | loge("Did not finish reading entire image; aborting"); |
| 8242 | return; |
| 8243 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8244 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 8245 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 8246 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 8247 | new CallComposerPictureTransfer.Factory() {}, |
| 8248 | imageData, |
| 8249 | (result) -> { |
| 8250 | if (result.first != null) { |
| 8251 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 8252 | Bundle outputResult = new Bundle(); |
| 8253 | outputResult.putParcelable( |
| 8254 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 8255 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 8256 | outputResult); |
| 8257 | } else { |
| 8258 | callback.send(result.second, null); |
| 8259 | } |
| 8260 | } |
| 8261 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 8262 | }); |
| 8263 | } |
| 8264 | |
| 8265 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8266 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8267 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8268 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8269 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8270 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8271 | PackageManager.FEATURE_TELEPHONY_IMS, "enableVideoCalling"); |
| 8272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8273 | final long identity = Binder.clearCallingIdentity(); |
| 8274 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8275 | ImsManager.getInstance(defaultPhone.getContext(), |
| 8276 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
| 8282 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8283 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8284 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 8286 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 8287 | return false; |
| 8288 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 8289 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8290 | enforceTelephonyFeatureWithException(callingPackage, |
| 8291 | PackageManager.FEATURE_TELEPHONY_IMS, "isVideoCallingEnabled"); |
| 8292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | final long identity = Binder.clearCallingIdentity(); |
| 8294 | try { |
| 8295 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 8296 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 8297 | // In the long run, we may instead need to check if there exists a connection service |
| 8298 | // which can support video calling. |
| 8299 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8300 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | return imsManager.isVtEnabledByPlatform() |
| 8302 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 8303 | && imsManager.isVtEnabledByUser(); |
| 8304 | } finally { |
| 8305 | Binder.restoreCallingIdentity(identity); |
| 8306 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 8307 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 8308 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8309 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8310 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 8311 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8312 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8313 | mApp, subId, callingPackage, callingFeatureId, |
| 8314 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | return false; |
| 8316 | } |
| 8317 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8318 | enforceTelephonyFeatureWithException(callingPackage, |
| 8319 | PackageManager.FEATURE_TELEPHONY_CALLING, "canChangeDtmfToneLength"); |
| 8320 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8321 | final long identity = Binder.clearCallingIdentity(); |
| 8322 | try { |
| 8323 | CarrierConfigManager configManager = |
| 8324 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8325 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8326 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 8327 | } finally { |
| 8328 | Binder.restoreCallingIdentity(identity); |
| 8329 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8330 | } |
| 8331 | |
| 8332 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8333 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8335 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8336 | return false; |
| 8337 | } |
| 8338 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8339 | enforceTelephonyFeatureWithException(callingPackage, |
| 8340 | PackageManager.FEATURE_TELEPHONY, "isWorldPhone"); |
| 8341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8342 | final long identity = Binder.clearCallingIdentity(); |
| 8343 | try { |
| 8344 | CarrierConfigManager configManager = |
| 8345 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8346 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8347 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 8348 | } finally { |
| 8349 | Binder.restoreCallingIdentity(identity); |
| 8350 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 8351 | } |
| 8352 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8353 | @Override |
| 8354 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8355 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 8356 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8357 | } |
| 8358 | |
| 8359 | @Override |
| 8360 | public boolean isHearingAidCompatibilitySupported() { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8361 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8362 | PackageManager.FEATURE_TELEPHONY_CALLING, "isHearingAidCompatibilitySupported"); |
| 8363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8364 | final long identity = Binder.clearCallingIdentity(); |
| 8365 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8366 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8367 | } finally { |
| 8368 | Binder.restoreCallingIdentity(identity); |
| 8369 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 8370 | } |
| 8371 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8372 | /** |
| 8373 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 8374 | * support for the feature and device firmware support. |
| 8375 | * |
| 8376 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 8377 | */ |
| 8378 | @Override |
| 8379 | public boolean isRttSupported(int subscriptionId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8380 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8381 | PackageManager.FEATURE_TELEPHONY_IMS, "isRttSupported"); |
| 8382 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8383 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8384 | final Phone phone = getPhone(subscriptionId); |
| 8385 | if (phone == null) { |
| 8386 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 8387 | return false; |
| 8388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8389 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8390 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8392 | boolean isDeviceSupported = (phone.getContext().getResources() != null) |
| 8393 | ? phone.getContext().getResources().getBoolean(R.bool.config_support_rtt) |
| 8394 | : false; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8395 | return isCarrierSupported && isDeviceSupported; |
| 8396 | } finally { |
| 8397 | Binder.restoreCallingIdentity(identity); |
| 8398 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 8399 | } |
| 8400 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 8401 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 8402 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 8403 | * RTT setting, will return true if the device and carrier both support RTT. |
| 8404 | * 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] | 8405 | */ |
| 8406 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | final long identity = Binder.clearCallingIdentity(); |
| 8408 | try { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8409 | if (mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) { |
| 8410 | if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) { |
| 8411 | return false; |
| 8412 | } |
| 8413 | } |
| 8414 | |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 8415 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 8416 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 8417 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 8418 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 8419 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 8420 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8421 | } finally { |
| 8422 | Binder.restoreCallingIdentity(identity); |
| 8423 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 8424 | } |
| 8425 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8426 | @Deprecated |
| 8427 | @Override |
| 8428 | public String getDeviceId(String callingPackage) { |
| 8429 | return getDeviceIdWithFeature(callingPackage, null); |
| 8430 | } |
| 8431 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8432 | /** |
| 8433 | * Returns the unique device ID of phone, for example, the IMEI for |
| 8434 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 8435 | * |
| 8436 | * <p>Requires Permission: |
| 8437 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 8438 | */ |
| 8439 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8440 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 8441 | try { |
| 8442 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 8443 | } catch (SecurityException se) { |
| 8444 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 8445 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 8446 | + Binder.getCallingUid()); |
| 8447 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8448 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8449 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8450 | return null; |
| 8451 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8452 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 8453 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8454 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 8455 | return null; |
| 8456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8457 | |
| 8458 | final long identity = Binder.clearCallingIdentity(); |
| 8459 | try { |
| 8460 | return phone.getDeviceId(); |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
| 8463 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 8464 | } |
| 8465 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8466 | /** |
| 8467 | * {@hide} |
| 8468 | * Returns the IMS Registration Status on a particular subid |
| 8469 | * |
| 8470 | * @param subId |
| 8471 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8472 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 8473 | Phone phone = getPhone(subId); |
| 8474 | if (phone != null) { |
| 8475 | return phone.isImsRegistered(); |
| 8476 | } else { |
| 8477 | return false; |
| 8478 | } |
| 8479 | } |
| 8480 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 8481 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8482 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8483 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8484 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8485 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 8486 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8487 | } |
| 8488 | final long identity = Binder.clearCallingIdentity(); |
| 8489 | try { |
| 8490 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 8491 | } finally { |
| 8492 | Binder.restoreCallingIdentity(identity); |
| 8493 | } |
| 8494 | } |
| 8495 | |
| 8496 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8497 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 8498 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8499 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8500 | mApp, |
| 8501 | subscriptionId, |
| 8502 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 8503 | + subscriptionId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8504 | |
| 8505 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8506 | PackageManager.FEATURE_TELEPHONY_CALLING, "getPhoneAccountHandleForSubscriptionId"); |
| 8507 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 8508 | final long identity = Binder.clearCallingIdentity(); |
| 8509 | try { |
| 8510 | Phone phone = getPhone(subscriptionId); |
| 8511 | if (phone == null) { |
| 8512 | return null; |
| 8513 | } |
| 8514 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 8515 | } finally { |
| 8516 | Binder.restoreCallingIdentity(identity); |
| 8517 | } |
| 8518 | } |
| 8519 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8520 | /** |
| 8521 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8522 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8523 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | final long identity = Binder.clearCallingIdentity(); |
| 8525 | try { |
| 8526 | Phone phone = getPhone(subId); |
| 8527 | if (phone != null) { |
| 8528 | return phone.isWifiCallingEnabled(); |
| 8529 | } else { |
| 8530 | return false; |
| 8531 | } |
| 8532 | } finally { |
| 8533 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8534 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 8535 | } |
| 8536 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8537 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8538 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8539 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8540 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | Phone phone = getPhone(subId); |
| 8544 | if (phone != null) { |
| 8545 | return phone.isVideoEnabled(); |
| 8546 | } else { |
| 8547 | return false; |
| 8548 | } |
| 8549 | } finally { |
| 8550 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8551 | } |
| 8552 | } |
| 8553 | |
| 8554 | /** |
| 8555 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 8556 | * defined in {@link ImsRegistrationImplBase}. |
| 8557 | */ |
| 8558 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8559 | final long identity = Binder.clearCallingIdentity(); |
| 8560 | try { |
| 8561 | Phone phone = getPhone(subId); |
| 8562 | if (phone != null) { |
| 8563 | return phone.getImsRegistrationTech(); |
| 8564 | } else { |
| 8565 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 8566 | } |
| 8567 | } finally { |
| 8568 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 8569 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 8570 | } |
| 8571 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8572 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8573 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 8574 | enforceSettingsPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8575 | |
| 8576 | enforceTelephonyFeatureWithException(callingPackage, |
| 8577 | PackageManager.FEATURE_TELEPHONY, "factoryReset"); |
| 8578 | |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8579 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 8580 | return; |
| 8581 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8582 | Phone defaultPhone = getDefaultPhone(); |
| 8583 | if (defaultPhone != null) { |
| 8584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8585 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 8586 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8587 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8588 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8589 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 8590 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 8591 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8592 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8593 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8594 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 8595 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8596 | cleanUpAllowedNetworkTypes(phone, subId); |
Rambo Wang | 71f6aa6 | 2024-02-23 20:16:22 +0000 | [diff] [blame] | 8597 | setDataRoamingEnabled(subId, phone == null ? false |
| 8598 | : phone.getDataSettingsManager().isDefaultDataRoamingEnabled()); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 8599 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8600 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8601 | // There has been issues when Sms raw table somehow stores orphan |
| 8602 | // fragments. They lead to garbled message when new fragments come |
| 8603 | // in and combined with those stale ones. In case this happens again, |
| 8604 | // user can reset all network settings which will clean up this table. |
| 8605 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8606 | // Clean up IMS settings as well here. |
| 8607 | int slotId = getSlotIndex(subId); |
Tomasz Wasilczyk | 2159ca2 | 2024-07-25 13:54:35 -0700 | [diff] [blame] | 8608 | if (isImsAvailableOnDevice() && slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 8609 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8610 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8611 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8612 | if (defaultPhone == null) { |
| 8613 | return; |
| 8614 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8615 | // Erase modem config if erase modem on network setting is enabled. |
| 8616 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8617 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8618 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8619 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8620 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8621 | |
| 8622 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8623 | } finally { |
| 8624 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8625 | } |
| 8626 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8627 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8628 | @VisibleForTesting |
| 8629 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8630 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8631 | return; |
| 8632 | } |
| 8633 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8634 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8635 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8636 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8637 | "user=" + defaultNetworkType); |
| 8638 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8639 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8640 | defaultNetworkType, null); |
| 8641 | } |
| 8642 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8643 | private void cleanUpSmsRawTable(Context context) { |
| 8644 | ContentResolver resolver = context.getContentResolver(); |
| 8645 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8646 | resolver.delete(uri, null, null); |
| 8647 | } |
| 8648 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8649 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8650 | public String getSimLocaleForSubscriber(int subId) { |
| 8651 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8652 | |
| 8653 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8654 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimLocaleForSubscriber"); |
| 8655 | |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8656 | final Phone phone = getPhone(subId); |
| 8657 | if (phone == null) { |
| 8658 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8659 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8661 | final long identity = Binder.clearCallingIdentity(); |
| 8662 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8663 | SubscriptionInfo info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
| 8664 | phone.getContext().getOpPackageName(), |
| 8665 | phone.getContext().getAttributionTag()); |
| 8666 | if (info == null) { |
| 8667 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8668 | return null; |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8669 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8670 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8671 | // preferences (EF-PL and EF-LI)... |
| 8672 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8673 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8674 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8675 | if (localeFromDefaultSim != null) { |
| 8676 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8677 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8678 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8679 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8680 | } else { |
| 8681 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8682 | } |
| 8683 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8684 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8685 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8686 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8687 | // the SIM and carrier preferences does not include a country we add the country |
| 8688 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8689 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8690 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8691 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8692 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | if (DBG) log("No locale found - returning null"); |
| 8696 | return null; |
| 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8700 | } |
| 8701 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8702 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8703 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8704 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8705 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8706 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8707 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8708 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8709 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8710 | return localeTag; |
| 8711 | } |
| 8712 | } |
| 8713 | return inputLocale.toLanguageTag(); |
| 8714 | } |
| 8715 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8716 | /** |
| 8717 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8718 | */ |
| 8719 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8720 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Ling Ma | 9fa6741 | 2023-11-13 14:13:19 -0800 | [diff] [blame] | 8721 | mApp.getOpPackageName(), mApp.getAttributionTag(), true/*isForAllProfile*/); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8722 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8723 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8724 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8725 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8726 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8727 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8728 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8729 | * representing the state of the modem. |
| 8730 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8731 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8732 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8733 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8734 | */ |
| 8735 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8736 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8737 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8738 | |
Tomasz Wasilczyk | 708d16e | 2024-09-12 14:49:51 -0700 | [diff] [blame] | 8739 | if (!mApp.getResources().getBoolean( |
| 8740 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 8741 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8742 | PackageManager.FEATURE_TELEPHONY, "requestModemActivityInfo"); |
| 8743 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8744 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8745 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8746 | |
| 8747 | final long identity = Binder.clearCallingIdentity(); |
| 8748 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8749 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8752 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8753 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8754 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8755 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8756 | // less than total activity duration. |
| 8757 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8758 | if (info == null) { |
| 8759 | return false; |
| 8760 | } |
| 8761 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8762 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8763 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8764 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8765 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8766 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8767 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8768 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8769 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8770 | } |
| 8771 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8772 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8773 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8774 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8775 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8776 | |
| 8777 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8778 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8779 | } |
| 8780 | |
| 8781 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8782 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8783 | rat, |
| 8784 | freq, |
| 8785 | info.getReceiveTimeMillis(rat, freq) |
| 8786 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8787 | } |
| 8788 | |
| 8789 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8790 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8791 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8792 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8793 | |
| 8794 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8795 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8796 | } |
| 8797 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8798 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8799 | rat, |
| 8800 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8801 | } |
| 8802 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8803 | /** |
| 8804 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8805 | * @param info recent ModemActivityInfo |
| 8806 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8807 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8808 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8809 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8810 | boolean matched; |
| 8811 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8812 | matched = false; |
| 8813 | int rat = info.getSpecificInfoRat(i); |
| 8814 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8815 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8816 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8817 | //if it already exists |
| 8818 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8819 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8820 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8821 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8822 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8823 | updateLastModemActivityInfo(info, rat, freq); |
| 8824 | matched = true; |
| 8825 | } |
| 8826 | } else { |
| 8827 | updateLastModemActivityInfo(info, rat); |
| 8828 | matched = true; |
| 8829 | } |
| 8830 | } |
| 8831 | } |
| 8832 | |
| 8833 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8834 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8835 | new ActivityStatsTechSpecificInfo( |
| 8836 | rat, |
| 8837 | freq, |
| 8838 | info.getTransmitTimeMillis(rat, freq), |
| 8839 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8840 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8841 | } |
| 8842 | } |
| 8843 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8844 | mLastModemActivitySpecificInfo = |
| 8845 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8846 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8847 | |
| 8848 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8849 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8850 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8851 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8852 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8853 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8854 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8855 | |
| 8856 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8857 | new ModemActivityInfo( |
| 8858 | mLastModemActivityInfo.getTimestampMillis(), |
| 8859 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8860 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8861 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8862 | } |
| 8863 | |
| 8864 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8865 | ActivityStatsTechSpecificInfo[] info) { |
| 8866 | int infoSize = info.length; |
| 8867 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8868 | for (int i = 0; i < infoSize; i++) { |
| 8869 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8870 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8871 | info[i].getTransmitTimeMillis(), |
| 8872 | (int) info[i].getReceiveTimeMillis()); |
| 8873 | } |
| 8874 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8875 | } |
| 8876 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8877 | /** |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8878 | * Returns the service state information on specified SIM slot. |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8879 | */ |
| 8880 | @Override |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8881 | public ServiceState getServiceStateForSlot(int slotIndex, boolean renounceFineLocationAccess, |
| 8882 | boolean renounceCoarseLocationAccess, String callingPackage, String callingFeatureId) { |
| 8883 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8884 | if (phone == null) { |
| 8885 | loge("getServiceStateForSlot retuning null for invalid slotIndex=" + slotIndex); |
| 8886 | return null; |
| 8887 | } |
| 8888 | |
| 8889 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8890 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8891 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8892 | return null; |
| 8893 | } |
| 8894 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8895 | enforceTelephonyFeatureWithException(callingPackage, |
| 8896 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getServiceStateForSubscriber"); |
| 8897 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8898 | boolean hasFinePermission = false; |
| 8899 | boolean hasCoarsePermission = false; |
| 8900 | if (!renounceFineLocationAccess) { |
| 8901 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8902 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8903 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8904 | .setCallingPackage(callingPackage) |
| 8905 | .setCallingFeatureId(callingFeatureId) |
| 8906 | .setCallingPid(Binder.getCallingPid()) |
| 8907 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8908 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8909 | .setLogAsInfo(true) |
| 8910 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8911 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8912 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8913 | .build()); |
| 8914 | hasFinePermission = |
| 8915 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8916 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8917 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8918 | if (!renounceCoarseLocationAccess) { |
| 8919 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8920 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8921 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8922 | .setCallingPackage(callingPackage) |
| 8923 | .setCallingFeatureId(callingFeatureId) |
| 8924 | .setCallingPid(Binder.getCallingPid()) |
| 8925 | .setCallingUid(Binder.getCallingUid()) |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8926 | .setMethod("getServiceStateForSlot") |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8927 | .setLogAsInfo(true) |
| 8928 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8929 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8930 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8931 | .build()); |
| 8932 | hasCoarsePermission = |
| 8933 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8934 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8935 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8936 | final long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8937 | try { |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8938 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
| 8939 | .getSubscriptionInfoInternal(subId); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8940 | if (subInfo != null && !subInfo.isActive()) { |
| 8941 | log("getServiceStateForSlot returning null for inactive subId=" + subId); |
Jack Yu | 3beaf9d | 2023-04-14 09:17:27 -0700 | [diff] [blame] | 8942 | return null; |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8943 | } |
| 8944 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8945 | ServiceState ss = phone.getServiceState(); |
Aishwarya Mallampati | 33a201a | 2024-05-09 20:39:09 +0000 | [diff] [blame] | 8946 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8947 | .contains(callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8948 | |
| 8949 | // Scrub out the location info in ServiceState depending on what level of access |
| 8950 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8951 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8952 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8953 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8954 | } finally { |
| 8955 | Binder.restoreCallingIdentity(identity); |
| 8956 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8957 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8958 | |
| 8959 | /** |
| 8960 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8961 | * |
| 8962 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8963 | * voicemail ringtone. |
| 8964 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8965 | * PhoneAccount. |
| 8966 | */ |
| 8967 | @Override |
| 8968 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 8969 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 8970 | PackageManager.FEATURE_TELEPHONY_CALLING, "getVoicemailRingtoneUri"); |
| 8971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8972 | final long identity = Binder.clearCallingIdentity(); |
| 8973 | try { |
| 8974 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8975 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8976 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8977 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8979 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8980 | } finally { |
| 8981 | Binder.restoreCallingIdentity(identity); |
| 8982 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8986 | * Sets the per-account voicemail ringtone. |
| 8987 | * |
| 8988 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8989 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8990 | * |
| 8991 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8992 | * voicemail ringtone. |
| 8993 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8994 | * PhoneAccount. |
| 8995 | */ |
| 8996 | @Override |
| 8997 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8998 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8999 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9000 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9001 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9002 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9004 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9005 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9006 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9007 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9008 | enforceTelephonyFeatureWithException(callingPackage, |
| 9009 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailRingtoneUri"); |
| 9010 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9011 | final long identity = Binder.clearCallingIdentity(); |
| 9012 | try { |
| 9013 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9014 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9015 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9016 | } |
| 9017 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 9018 | } finally { |
| 9019 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9020 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9021 | } |
| 9022 | |
| 9023 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9024 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 9025 | * |
| 9026 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 9027 | * voicemail vibration setting. |
| 9028 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 9029 | */ |
| 9030 | @Override |
| 9031 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9032 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9033 | PackageManager.FEATURE_TELEPHONY_CALLING, "isVoicemailVibrationEnabled"); |
| 9034 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9035 | final long identity = Binder.clearCallingIdentity(); |
| 9036 | try { |
| 9037 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 9038 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9039 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9040 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9042 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 9043 | } finally { |
| 9044 | Binder.restoreCallingIdentity(identity); |
| 9045 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 9046 | } |
| 9047 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9048 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9049 | * Sets the per-account voicemail vibration. |
| 9050 | * |
| 9051 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 9052 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9053 | * |
| 9054 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 9055 | * voicemail vibration setting. |
| 9056 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 9057 | * specific PhoneAccount. |
| 9058 | */ |
| 9059 | @Override |
| 9060 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 9061 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9062 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9063 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 9064 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 9065 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9066 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9067 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 9068 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9069 | } |
| 9070 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9071 | enforceTelephonyFeatureWithException(callingPackage, |
| 9072 | PackageManager.FEATURE_TELEPHONY_CALLING, "setVoicemailVibrationEnabled"); |
| 9073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9074 | final long identity = Binder.clearCallingIdentity(); |
| 9075 | try { |
| 9076 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 9077 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9078 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9079 | } |
| 9080 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 9081 | } finally { |
| 9082 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9083 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 9084 | } |
| 9085 | |
| 9086 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9087 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 9088 | * |
| 9089 | * @throws SecurityException if the caller does not have the required permission |
| 9090 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9091 | @VisibleForTesting |
| 9092 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9093 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9094 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9095 | } |
| 9096 | |
| 9097 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9098 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 9099 | * permission. |
| 9100 | * |
| 9101 | * @throws SecurityException if the caller does not have the required permission |
| 9102 | */ |
| 9103 | private void enforceSendSmsPermission() { |
| 9104 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 9105 | } |
| 9106 | |
| 9107 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 9108 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 9109 | * users permission. |
| 9110 | * |
| 9111 | * @throws SecurityException if the caller does not have the required permission |
| 9112 | */ |
| 9113 | private void enforceInteractAcrossUsersPermission(String message) { |
| 9114 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 9115 | } |
| 9116 | |
| 9117 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9118 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9119 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9120 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9121 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 9122 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9123 | final long identity = Binder.clearCallingIdentity(); |
| 9124 | try { |
| 9125 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9126 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9127 | if (componentName == null) { |
| 9128 | throw new SecurityException( |
| 9129 | "Caller not current active visual voicemail package[null]"); |
| 9130 | } |
| 9131 | String vvmPackage = componentName.getPackageName(); |
| 9132 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 9133 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9134 | } |
| 9135 | } finally { |
| 9136 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 9137 | } |
| 9138 | } |
| 9139 | |
| 9140 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9141 | * Return the application ID for the app type. |
| 9142 | * |
| 9143 | * @param subId the subscription ID that this request applies to. |
| 9144 | * @param appType the uicc app type. |
| 9145 | * @return Application ID for specificied app type, or null if no uicc. |
| 9146 | */ |
| 9147 | @Override |
| 9148 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9149 | enforceReadPrivilegedPermission("getAidForAppType"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9150 | |
| 9151 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9152 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getAidForAppType"); |
| 9153 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9154 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9155 | |
| 9156 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9157 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9158 | if (phone == null) { |
| 9159 | return null; |
| 9160 | } |
| 9161 | String aid = null; |
| 9162 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9163 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9164 | .getApplicationByType(appType).getAid(); |
| 9165 | } catch (Exception e) { |
| 9166 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 9167 | } |
| 9168 | return aid; |
| 9169 | } finally { |
| 9170 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9171 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 9172 | } |
| 9173 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9174 | /** |
| 9175 | * Return the Electronic Serial Number. |
| 9176 | * |
| 9177 | * @param subId the subscription ID that this request applies to. |
| 9178 | * @return ESN or null if error. |
| 9179 | */ |
| 9180 | @Override |
| 9181 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9182 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9183 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9184 | |
| 9185 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9186 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9187 | if (phone == null) { |
| 9188 | return null; |
| 9189 | } |
| 9190 | String esn = null; |
| 9191 | try { |
| 9192 | esn = phone.getEsn(); |
| 9193 | } catch (Exception e) { |
| 9194 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 9195 | } |
| 9196 | return esn; |
| 9197 | } finally { |
| 9198 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9199 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 9200 | } |
| 9201 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9202 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9203 | * Return the Preferred Roaming List Version. |
| 9204 | * |
| 9205 | * @param subId the subscription ID that this request applies to. |
| 9206 | * @return PRLVersion or null if error. |
| 9207 | */ |
| 9208 | @Override |
| 9209 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9210 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9211 | |
| 9212 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9213 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaPrlVersion"); |
| 9214 | |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9215 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9216 | |
| 9217 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9218 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9219 | if (phone == null) { |
| 9220 | return null; |
| 9221 | } |
| 9222 | String cdmaPrlVersion = null; |
| 9223 | try { |
| 9224 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 9225 | } catch (Exception e) { |
| 9226 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 9227 | } |
| 9228 | return cdmaPrlVersion; |
| 9229 | } finally { |
| 9230 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9231 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 9232 | } |
| 9233 | |
| 9234 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9235 | * Get snapshot of Telephony histograms |
| 9236 | * @return List of Telephony histograms |
| 9237 | * @hide |
| 9238 | */ |
| 9239 | @Override |
| 9240 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9242 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9243 | |
| 9244 | final long identity = Binder.clearCallingIdentity(); |
| 9245 | try { |
| 9246 | return RIL.getTelephonyRILTimingHistograms(); |
| 9247 | } finally { |
| 9248 | Binder.restoreCallingIdentity(identity); |
| 9249 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 9250 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9251 | |
| 9252 | /** |
| 9253 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9254 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 9255 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9256 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9257 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9258 | * @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] | 9259 | */ |
| 9260 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9261 | @TelephonyManager.SetCarrierRestrictionResult |
| 9262 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9263 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9264 | |
| 9265 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9266 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setAllowedCarriers"); |
| 9267 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9268 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9269 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9270 | if (carrierRestrictionRules == null) { |
| 9271 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 9272 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9274 | final long identity = Binder.clearCallingIdentity(); |
| 9275 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9276 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9277 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9278 | } finally { |
| 9279 | Binder.restoreCallingIdentity(identity); |
| 9280 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9281 | } |
| 9282 | |
| 9283 | /** |
| 9284 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9285 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 9286 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9287 | * Require system privileges. In the future we may add this to carrier APIs. |
| 9288 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9289 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9290 | */ |
| 9291 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9292 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9293 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9294 | |
| 9295 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9296 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "getAllowedCarriers"); |
| 9297 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9298 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9299 | |
| 9300 | final long identity = Binder.clearCallingIdentity(); |
| 9301 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 9302 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 9303 | if (response instanceof CarrierRestrictionRules) { |
| 9304 | return (CarrierRestrictionRules) response; |
| 9305 | } |
| 9306 | // Response is an Exception of some kind, |
| 9307 | // which is signalled to the user as a NULL retval |
| 9308 | return null; |
| 9309 | } catch (Exception e) { |
| 9310 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 9311 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9312 | } finally { |
| 9313 | Binder.restoreCallingIdentity(identity); |
| 9314 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 9315 | } |
| 9316 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9317 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9318 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 9319 | * through the callback. |
| 9320 | * |
| 9321 | * @param callback The callback that will be used to send the result. |
| 9322 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 9323 | * the caller is not allowlisted. |
| 9324 | */ |
| 9325 | @Override |
| 9326 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9327 | String functionName = "getCarrierRestrictionStatus"; |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9328 | enforceTelephonyFeatureWithException(packageName, |
arunvoddu | 181c74f | 2024-08-19 14:21:29 +0000 | [diff] [blame] | 9329 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, functionName); |
| 9330 | try { |
| 9331 | mApp.enforceCallingOrSelfPermission( |
| 9332 | android.Manifest.permission.READ_BASIC_PHONE_STATE, |
| 9333 | functionName); |
| 9334 | } catch (SecurityException e) { |
| 9335 | mApp.enforceCallingOrSelfPermission(permission.READ_PHONE_STATE, |
| 9336 | functionName); |
| 9337 | } |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9338 | Set<Integer> carrierIds = validateCallerAndGetCarrierIds(packageName); |
| 9339 | if (carrierIds.contains(CarrierAllowListInfo.INVALID_CARRIER_ID)) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9340 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 9341 | throw new SecurityException("Not an authorized caller"); |
| 9342 | } |
| 9343 | final long identity = Binder.clearCallingIdentity(); |
| 9344 | try { |
| 9345 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9346 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierIds); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9347 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 9348 | } finally { |
| 9349 | Binder.restoreCallingIdentity(identity); |
| 9350 | } |
| 9351 | } |
| 9352 | |
arunvoddu | 567f2b4 | 2023-04-25 17:22:00 +0000 | [diff] [blame] | 9353 | @Override |
| 9354 | public List<String> getShaIdFromAllowList(String pkgName, int carrierId) { |
| 9355 | enforceReadPrivilegedPermission("checkCarrierRestrictionFileForNoChange"); |
| 9356 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 9357 | return allowListInfo.getShaIdList(pkgName, carrierId); |
| 9358 | } |
| 9359 | |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9360 | @VisibleForTesting |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9361 | public Set<Integer> validateCallerAndGetCarrierIds(String packageName) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9362 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 9363 | return allowListInfo.validateCallerAndGetCarrierIds(packageName); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 9364 | } |
| 9365 | |
| 9366 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9367 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 9368 | * @param subId the subscription ID that this action applies to. |
| 9369 | * @param enabled control enable or disable radio. |
| 9370 | * {@hide} |
| 9371 | */ |
| 9372 | @Override |
| 9373 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 9374 | enforceModifyPermission(); |
| 9375 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9376 | |
| 9377 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9378 | if (phone == null) { |
| 9379 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 9380 | return; |
| 9381 | } |
| 9382 | try { |
| 9383 | phone.carrierActionSetRadioEnabled(enabled); |
| 9384 | } catch (Exception e) { |
| 9385 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9386 | } finally { |
| 9387 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 9388 | } |
| 9389 | } |
| 9390 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9391 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9392 | * Enable or disable Voice over NR (VoNR) |
| 9393 | * @param subId the subscription ID that this action applies to. |
| 9394 | * @param enabled enable or disable VoNR. |
| 9395 | * @return operation result. |
| 9396 | */ |
| 9397 | @Override |
| 9398 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 9399 | enforceModifyPermission(); |
| 9400 | final Phone phone = getPhone(subId); |
| 9401 | |
| 9402 | final long identity = Binder.clearCallingIdentity(); |
| 9403 | if (phone == null) { |
| 9404 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 9405 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 9406 | } |
| 9407 | |
| 9408 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9409 | try { |
| 9410 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 9411 | workSource); |
| 9412 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 9413 | |
| 9414 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 9415 | if (DBG) { |
| 9416 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 9417 | } |
| 9418 | SubscriptionManager.setSubscriptionProperty( |
| 9419 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 9420 | (enabled ? "1" : "0")); |
| 9421 | } |
| 9422 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 9423 | return result; |
| 9424 | } finally { |
| 9425 | Binder.restoreCallingIdentity(identity); |
| 9426 | } |
| 9427 | } |
| 9428 | |
| 9429 | /** |
| 9430 | * Is voice over NR enabled |
| 9431 | * @return true if VoNR is enabled else false |
| 9432 | */ |
| 9433 | @Override |
| 9434 | public boolean isVoNrEnabled(int subId) { |
| 9435 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 9436 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9437 | final long identity = Binder.clearCallingIdentity(); |
| 9438 | try { |
| 9439 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 9440 | null, subId, workSource); |
| 9441 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 9442 | return isEnabled; |
| 9443 | } finally { |
| 9444 | Binder.restoreCallingIdentity(identity); |
| 9445 | } |
| 9446 | } |
| 9447 | |
| 9448 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9449 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 9450 | * network status based on which carrier apps could apply actions accordingly, |
| 9451 | * enable/disable default url handler for example. |
| 9452 | * |
| 9453 | * @param subId the subscription ID that this action applies to. |
| 9454 | * @param report control start/stop reporting the default network status. |
| 9455 | * {@hide} |
| 9456 | */ |
| 9457 | @Override |
| 9458 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 9459 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9460 | |
| 9461 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9462 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 9463 | "carrierActionReportDefaultNetworkStatus"); |
| 9464 | |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9465 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9466 | |
| 9467 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9468 | if (phone == null) { |
| 9469 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 9470 | return; |
| 9471 | } |
| 9472 | try { |
| 9473 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 9474 | } catch (Exception e) { |
| 9475 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9476 | } finally { |
| 9477 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 9478 | } |
| 9479 | } |
| 9480 | |
| 9481 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9482 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 9483 | * @param subId the subscription ID that this action applies to. |
| 9484 | * {@hide} |
| 9485 | */ |
| 9486 | @Override |
| 9487 | public void carrierActionResetAll(int subId) { |
| 9488 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9489 | |
| 9490 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9491 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "carrierActionResetAll"); |
| 9492 | |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 9493 | final Phone phone = getPhone(subId); |
| 9494 | if (phone == null) { |
| 9495 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 9496 | return; |
| 9497 | } |
| 9498 | try { |
| 9499 | phone.carrierActionResetAll(); |
| 9500 | } catch (Exception e) { |
| 9501 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 9502 | } |
| 9503 | } |
| 9504 | |
| 9505 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9506 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 9507 | * bug report is being generated. |
| 9508 | */ |
| 9509 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 9510 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9511 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 9512 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 9513 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 9514 | + Binder.getCallingPid() |
| 9515 | + ", uid=" + Binder.getCallingUid() |
| 9516 | + "without permission " |
| 9517 | + android.Manifest.permission.DUMP); |
| 9518 | return; |
| 9519 | } |
Allen Xu | 4574a1a | 2024-05-13 23:10:02 +0000 | [diff] [blame] | 9520 | try { |
| 9521 | DumpsysHandler.dump(mApp, fd, writer, args); |
| 9522 | } catch (Exception e) { |
| 9523 | writer.println("Failed to dump phone information: " + e); |
| 9524 | } |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 9525 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9526 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9527 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 9528 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 9529 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 9530 | @NonNull String[] args) { |
| 9531 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 9532 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9533 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 9534 | } |
| 9535 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 9536 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9537 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 9538 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9539 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9540 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9541 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9542 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9543 | */ |
| 9544 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9545 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 9546 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9547 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 9548 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9549 | try { |
| 9550 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 9551 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9552 | } catch (SecurityException se) { |
| 9553 | enforceModifyPermission(); |
| 9554 | } |
| 9555 | } else { |
| 9556 | enforceModifyPermission(); |
| 9557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9558 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9559 | enforceTelephonyFeatureWithException(callingPackage, |
| 9560 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataEnabledForReason"); |
| 9561 | |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9562 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9563 | final long identity = Binder.clearCallingIdentity(); |
| 9564 | try { |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9565 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER && enabled |
| 9566 | && null != callingPackage && opEnableMobileDataByUser()) { |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 9567 | mAppOps.noteOpNoThrow(AppOpsManager.OPSTR_ENABLE_MOBILE_DATA_BY_USER, |
Nate Myren | 116695d | 2024-02-09 09:36:01 -0800 | [diff] [blame] | 9568 | callingUid, callingPackage, null, null); |
| 9569 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9570 | Phone phone = getPhone(subId); |
| 9571 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9572 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 9573 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 9574 | } else if (phone.getDataSettingsManager() != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9575 | phone.getDataSettingsManager().setDataEnabled( |
| 9576 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 9577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9578 | } |
| 9579 | } finally { |
| 9580 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 9581 | } |
| 9582 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9583 | |
| 9584 | /** |
| 9585 | * Get Client request stats |
| 9586 | * @return List of Client Request Stats |
| 9587 | * @hide |
| 9588 | */ |
| 9589 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9590 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 9591 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 9592 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9593 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9594 | return null; |
| 9595 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9596 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9598 | final long identity = Binder.clearCallingIdentity(); |
| 9599 | try { |
| 9600 | if (phone != null) { |
| 9601 | return phone.getClientRequestStats(); |
| 9602 | } |
| 9603 | |
| 9604 | return null; |
| 9605 | } finally { |
| 9606 | Binder.restoreCallingIdentity(identity); |
| 9607 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9608 | } |
| 9609 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9610 | private WorkSource getWorkSource(int uid) { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 9611 | PackageManager pm; |
| 9612 | if (mFeatureFlags.hsumPackageManager()) { |
| 9613 | pm = mApp.getBaseContext().createContextAsUser(UserHandle.getUserHandleForUid(uid), 0) |
| 9614 | .getPackageManager(); |
| 9615 | } else { |
| 9616 | pm = mApp.getPackageManager(); |
| 9617 | } |
| 9618 | |
| 9619 | String packageName = pm.getNameForUid(uid); |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 9620 | if (UserHandle.isSameApp(uid, Process.ROOT_UID) && packageName == null) { |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 9621 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 9622 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 9623 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 9624 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 9625 | // commands that plumb through the RIL as root, like so: |
| 9626 | // $ adb root |
| 9627 | // $ adb shell cmd phone ... |
| 9628 | packageName = "root"; |
| 9629 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 9630 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 9631 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9632 | |
| 9633 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9634 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9635 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9636 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9637 | * @param state State of SIM (power down, power up, pass through) |
| 9638 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9639 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9640 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9641 | * |
| 9642 | **/ |
| 9643 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 9644 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9645 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9646 | |
| 9647 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9648 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimPowerStateForSlot"); |
| 9649 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 9650 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9651 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 9652 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9654 | final long identity = Binder.clearCallingIdentity(); |
| 9655 | try { |
| 9656 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9657 | phone.setSimPowerState(state, null, workSource); |
| 9658 | } |
| 9659 | } finally { |
| 9660 | Binder.restoreCallingIdentity(identity); |
| 9661 | } |
| 9662 | } |
| 9663 | |
| 9664 | /** |
| 9665 | * Set SIM card power state. |
| 9666 | * |
| 9667 | * @param slotIndex SIM slot id. |
| 9668 | * @param state State of SIM (power down, power up, pass through) |
| 9669 | * @param callback callback to trigger after success or failure |
| 9670 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 9671 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 9672 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 9673 | * |
| 9674 | **/ |
| 9675 | @Override |
| 9676 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9677 | IIntegerConsumer callback) { |
| 9678 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9679 | |
| 9680 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9681 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 9682 | "setSimPowerStateForSlotWithCallback"); |
| 9683 | |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 9684 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9685 | |
| 9686 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9687 | |
| 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
| 9690 | if (phone != null) { |
| 9691 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9692 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9693 | } |
| 9694 | } finally { |
| 9695 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9696 | } |
| 9697 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9698 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9699 | private boolean isUssdApiAllowed(int subId) { |
| 9700 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9701 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9702 | if (configManager == null) { |
| 9703 | return false; |
| 9704 | } |
| 9705 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9706 | if (pb == null) { |
| 9707 | return false; |
| 9708 | } |
| 9709 | return pb.getBoolean( |
| 9710 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9711 | } |
| 9712 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9713 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9714 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9715 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9716 | * @param subId sub Id, but the check is in fact irrlevant to sub Id. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9717 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9718 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9719 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9720 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9721 | |
| 9722 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9723 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyCallbackMode"); |
| 9724 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9725 | final long identity = Binder.clearCallingIdentity(); |
| 9726 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9727 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9728 | } finally { |
| 9729 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9730 | } |
| 9731 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9732 | |
| 9733 | /** |
| 9734 | * Get the current signal strength information for the given subscription. |
| 9735 | * Because this information is not updated when the device is in a low power state |
| 9736 | * it should not be relied-upon to be current. |
| 9737 | * @param subId Subscription index |
| 9738 | * @return the most recent cached signal strength info from the modem |
| 9739 | */ |
| 9740 | @Override |
| 9741 | public SignalStrength getSignalStrength(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9742 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9743 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSignalStrength"); |
| 9744 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
| 9747 | Phone p = getPhone(subId); |
| 9748 | if (p == null) { |
| 9749 | return null; |
| 9750 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9752 | return p.getSignalStrength(); |
| 9753 | } finally { |
| 9754 | Binder.restoreCallingIdentity(identity); |
| 9755 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9756 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9757 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9758 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9759 | * Get the current modem radio state for the given slot. |
| 9760 | * @param slotIndex slot index. |
| 9761 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9762 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9763 | * @return the current radio power state from the modem |
| 9764 | */ |
| 9765 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9766 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9767 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9768 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9769 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9770 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9771 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9772 | } |
| 9773 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9774 | enforceTelephonyFeatureWithException(callingPackage, |
| 9775 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getRadioPowerState"); |
| 9776 | |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9777 | final long identity = Binder.clearCallingIdentity(); |
| 9778 | try { |
| 9779 | return phone.getRadioPowerState(); |
| 9780 | } finally { |
| 9781 | Binder.restoreCallingIdentity(identity); |
| 9782 | } |
| 9783 | } |
| 9784 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9785 | } |
| 9786 | |
| 9787 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9788 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9789 | * |
| 9790 | * <p>Requires one of the following permissions: |
| 9791 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9792 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9793 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9794 | * privileges. |
| 9795 | * |
| 9796 | * @param subId subscription id |
| 9797 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9798 | * {@code false}. |
| 9799 | */ |
| 9800 | @Override |
| 9801 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9802 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9803 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9804 | try { |
| 9805 | mApp.enforceCallingOrSelfPermission( |
| 9806 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9807 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9808 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9809 | mApp.enforceCallingOrSelfPermission( |
| 9810 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9811 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9812 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9813 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9814 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9815 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9816 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9817 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9818 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataRoamingEnabled"); |
| 9819 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9820 | boolean isEnabled = false; |
| 9821 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9822 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9823 | Phone phone = getPhone(subId); |
| 9824 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9825 | } finally { |
| 9826 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9827 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9828 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9829 | } |
| 9830 | |
| 9831 | |
| 9832 | /** |
| 9833 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9834 | * |
| 9835 | * <p> Requires permission: |
| 9836 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9837 | * privileges. |
| 9838 | * |
| 9839 | * @param subId subscription id |
| 9840 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9841 | */ |
| 9842 | @Override |
| 9843 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9844 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9845 | mApp, subId, "setDataRoamingEnabled"); |
| 9846 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9847 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9848 | PackageManager.FEATURE_TELEPHONY_DATA, "setDataRoamingEnabled"); |
| 9849 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9850 | final long identity = Binder.clearCallingIdentity(); |
| 9851 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9852 | Phone phone = getPhone(subId); |
| 9853 | if (phone != null) { |
| 9854 | phone.setDataRoamingEnabled(isEnabled); |
| 9855 | } |
| 9856 | } finally { |
| 9857 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9858 | } |
| 9859 | } |
| 9860 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9861 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9862 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9863 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9864 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9865 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9866 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9867 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 9868 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "isManualNetworkSelectionAllowed"); |
| 9869 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9870 | boolean isAllowed = true; |
| 9871 | final long identity = Binder.clearCallingIdentity(); |
| 9872 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9873 | Phone phone = getPhone(subId); |
| 9874 | if (phone != null) { |
| 9875 | isAllowed = phone.isCspPlmnEnabled(); |
| 9876 | } |
| 9877 | } finally { |
| 9878 | Binder.restoreCallingIdentity(identity); |
| 9879 | } |
| 9880 | return isAllowed; |
| 9881 | } |
| 9882 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9883 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9884 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9885 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9886 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9887 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9888 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9889 | if (phone == null) { |
| 9890 | return false; |
| 9891 | } |
| 9892 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9893 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9894 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9895 | } |
| 9896 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9897 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9898 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9899 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9900 | mApp.getSystemService(AppOpsManager.class) |
| 9901 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9902 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9903 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9904 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9905 | try { |
| 9906 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9907 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9908 | } catch (SecurityException e) { |
| 9909 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9910 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9911 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9912 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9913 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9914 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9915 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 9916 | |
| 9917 | enforceTelephonyFeatureWithException(callingPackage, |
| 9918 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccCardsInfo"); |
| 9919 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9920 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9921 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9922 | Binder.getCallingUid())) { |
| 9923 | isIccIdAccessRestricted = true; |
| 9924 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9925 | final long identity = Binder.clearCallingIdentity(); |
| 9926 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9927 | UiccController uiccController = UiccController.getInstance(); |
| 9928 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9929 | if (hasReadPermission) { |
| 9930 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9931 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9932 | |
| 9933 | // Remove private info if the caller doesn't have access |
| 9934 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9935 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9936 | //setting the value after compatibility check |
| 9937 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9938 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9939 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9940 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9941 | if (card == null) { |
| 9942 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9943 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9944 | continue; |
| 9945 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9946 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9947 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9948 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9949 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9950 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9951 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9952 | for (UiccPortInfo portInfo : portInfos) { |
| 9953 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9954 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9955 | if (port == null) { |
| 9956 | // assume no access if port is null |
| 9957 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9958 | continue; |
| 9959 | } |
| 9960 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9961 | uiccPortInfos.add(portInfo); |
| 9962 | } else { |
| 9963 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9964 | } |
| 9965 | } |
| 9966 | filteredInfos.add(new UiccCardInfo( |
| 9967 | cardInfo.isEuicc(), |
| 9968 | cardInfo.getCardId(), |
| 9969 | null, |
| 9970 | cardInfo.getPhysicalSlotIndex(), |
| 9971 | cardInfo.isRemovable(), |
| 9972 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9973 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9974 | } |
| 9975 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9976 | } finally { |
| 9977 | Binder.restoreCallingIdentity(identity); |
| 9978 | } |
| 9979 | } |
| 9980 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9981 | /** |
| 9982 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9983 | * generally private and require carrier privileges to view. |
| 9984 | * |
| 9985 | * @hide |
| 9986 | */ |
| 9987 | @NonNull |
| 9988 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9989 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9990 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9991 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9992 | } |
| 9993 | return new UiccCardInfo( |
| 9994 | cardInfo.isEuicc(), |
| 9995 | cardInfo.getCardId(), |
| 9996 | null, |
| 9997 | cardInfo.getPhysicalSlotIndex(), |
| 9998 | cardInfo.isRemovable(), |
| 9999 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 10000 | portinfo |
| 10001 | ); |
| 10002 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10003 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10004 | /** |
| 10005 | * @hide |
| 10006 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 10007 | * These values are generally private and require carrier privileges to view. |
| 10008 | */ |
| 10009 | @NonNull |
| 10010 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 10011 | return new UiccPortInfo( |
| 10012 | UiccPortInfo.ICCID_REDACTED, |
| 10013 | portInfo.getPortIndex(), |
| 10014 | portInfo.getLogicalSlotIndex(), |
| 10015 | portInfo.isActive() |
| 10016 | ); |
| 10017 | } |
| 10018 | @Override |
| 10019 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10020 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10021 | mApp.getSystemService(AppOpsManager.class) |
| 10022 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 10023 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10024 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10025 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10026 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 10027 | // we are reading iccId which is PII data. |
| 10028 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10029 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10030 | enforceTelephonyFeatureWithException(callingPackage, |
| 10031 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getUiccSlotsInfo"); |
| 10032 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10033 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 10034 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 10035 | Binder.getCallingUid())) { |
| 10036 | isLogicalSlotAccessRestricted = true; |
| 10037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10038 | final long identity = Binder.clearCallingIdentity(); |
| 10039 | try { |
| 10040 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 10041 | if (slots == null || slots.length == 0) { |
| 10042 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10043 | return null; |
| 10044 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10045 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 10046 | for (int i = 0; i < slots.length; i++) { |
| 10047 | UiccSlot slot = slots[i]; |
| 10048 | if (slot == null) { |
| 10049 | continue; |
| 10050 | } |
| 10051 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10052 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10053 | UiccCard card = slot.getUiccCard(); |
| 10054 | if (card != null) { |
| 10055 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 10056 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10057 | cardId = slot.getEid(); |
| 10058 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10059 | // If cardId is null, use iccId of default port as cardId. |
| 10060 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 10061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10062 | } |
| 10063 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 10064 | if (cardId != null) { |
| 10065 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 10066 | // if cardId is an EID, it's all digits so this is fine |
| 10067 | cardId = IccUtils.stripTrailingFs(cardId); |
| 10068 | } |
| 10069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10070 | int cardState = 0; |
| 10071 | switch (slot.getCardState()) { |
| 10072 | case CARDSTATE_ABSENT: |
| 10073 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 10074 | break; |
| 10075 | case CARDSTATE_PRESENT: |
| 10076 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 10077 | break; |
| 10078 | case CARDSTATE_ERROR: |
| 10079 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 10080 | break; |
| 10081 | case CARDSTATE_RESTRICTED: |
| 10082 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 10083 | break; |
| 10084 | default: |
| 10085 | break; |
| 10086 | |
| 10087 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10088 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 10089 | int[] portIndexes = slot.getPortList(); |
| 10090 | for (int portIdx : portIndexes) { |
| 10091 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 10092 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 10093 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 10094 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10095 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10096 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10097 | slot.isEuicc(), |
| 10098 | cardId, |
| 10099 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 10100 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10101 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10102 | //setting the value after compatibility check |
| 10103 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10104 | } |
| 10105 | return infos; |
| 10106 | } finally { |
| 10107 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 10108 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10109 | } |
| 10110 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10111 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 10112 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 10113 | boolean hasReadPermission) { |
| 10114 | String iccId = slot.getIccId(portIndex); |
| 10115 | if (hasReadPermission) { // if has read permission |
| 10116 | return iccId; |
| 10117 | } else { |
| 10118 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 10119 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 10120 | // if no read permission, checking carrier privilege access |
| 10121 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 10122 | return iccId; |
| 10123 | } |
| 10124 | } |
| 10125 | } |
| 10126 | // No read permission or carrier privilege access. |
| 10127 | return UiccPortInfo.ICCID_REDACTED; |
| 10128 | } |
| 10129 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10130 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10131 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10132 | public boolean switchSlots(int[] physicalSlots) { |
| 10133 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10134 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10135 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10136 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchSlots"); |
| 10137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10138 | final long identity = Binder.clearCallingIdentity(); |
| 10139 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10140 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 10141 | for (int i = 0; i < physicalSlots.length; i++) { |
| 10142 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 10143 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 10144 | physicalSlots[i], i)); |
| 10145 | } |
| 10146 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10147 | } finally { |
| 10148 | Binder.restoreCallingIdentity(identity); |
| 10149 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 10150 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 10151 | |
| 10152 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10153 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 10154 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 10155 | enforceModifyPermission(); |
| 10156 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10157 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10158 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setSimSlotMapping"); |
| 10159 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10160 | final long identity = Binder.clearCallingIdentity(); |
| 10161 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 10162 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 10163 | } finally { |
| 10164 | Binder.restoreCallingIdentity(identity); |
| 10165 | } |
| 10166 | } |
| 10167 | |
| 10168 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10169 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10170 | enforceTelephonyFeatureWithException(callingPackage, |
| 10171 | PackageManager.FEATURE_TELEPHONY_EUICC, "getCardIdForDefaultEuicc"); |
| 10172 | |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 10173 | final long identity = Binder.clearCallingIdentity(); |
| 10174 | try { |
| 10175 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 10176 | } finally { |
| 10177 | Binder.restoreCallingIdentity(identity); |
| 10178 | } |
| 10179 | } |
| 10180 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10181 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10182 | * A test API to reload the UICC profile. |
| 10183 | * |
| 10184 | * <p>Requires that the calling app has permission |
| 10185 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 10186 | * @hide |
| 10187 | */ |
| 10188 | @Override |
| 10189 | public void refreshUiccProfile(int subId) { |
| 10190 | enforceModifyPermission(); |
| 10191 | |
| 10192 | final long identity = Binder.clearCallingIdentity(); |
| 10193 | try { |
| 10194 | Phone phone = getPhone(subId); |
| 10195 | if (phone == null) { |
| 10196 | return; |
| 10197 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10198 | UiccPort uiccPort = phone.getUiccPort(); |
| 10199 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10200 | return; |
| 10201 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10202 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 10203 | if (uiccProfile == null) { |
| 10204 | return; |
| 10205 | } |
| 10206 | uiccProfile.refresh(); |
| 10207 | } finally { |
| 10208 | Binder.restoreCallingIdentity(identity); |
| 10209 | } |
| 10210 | } |
| 10211 | |
| 10212 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10213 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 10214 | */ |
| 10215 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10216 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10217 | } |
| 10218 | |
| 10219 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10220 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 10221 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 10222 | */ |
| 10223 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10224 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 10225 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 10226 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 10227 | return list.get(phoneId); |
| 10228 | } |
| 10229 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 10230 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10231 | |
| 10232 | @Override |
| 10233 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 10234 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10235 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10236 | |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
| 10239 | final Phone phone = getPhone(subId); |
| 10240 | if (phone == null) { |
| 10241 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 10242 | return; |
| 10243 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 10244 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10245 | if (cpt != null) { |
| 10246 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 10247 | } |
| 10248 | // 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] | 10249 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 10250 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 10251 | if (carrierPrivilegeRules == null) { |
| 10252 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 10253 | } else { |
| 10254 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 10255 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10256 | } finally { |
| 10257 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10258 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10259 | } |
| 10260 | |
| 10261 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10262 | public void setCarrierServicePackageOverride( |
| 10263 | int subId, String carrierServicePackage, String callingPackage) { |
| 10264 | TelephonyPermissions.enforceShellOnly( |
| 10265 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 10266 | |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 10267 | final long identity = Binder.clearCallingIdentity(); |
| 10268 | try { |
| 10269 | final Phone phone = getPhone(subId); |
| 10270 | if (phone == null || phone.getSubId() != subId) { |
| 10271 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 10272 | throw new IllegalArgumentException("No phone for subid"); |
| 10273 | } |
| 10274 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 10275 | if (cpt == null) { |
| 10276 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 10277 | throw new IllegalStateException("No CPT for phone"); |
| 10278 | } |
| 10279 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 10280 | } finally { |
| 10281 | Binder.restoreCallingIdentity(identity); |
| 10282 | } |
| 10283 | } |
| 10284 | |
| 10285 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10286 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 10287 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 10288 | |
| 10289 | final long identity = Binder.clearCallingIdentity(); |
| 10290 | try { |
| 10291 | final Phone phone = getPhone(subId); |
| 10292 | if (phone == null) { |
| 10293 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 10294 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 10295 | } |
| 10296 | return phone.getCarrierIdListVersion(); |
| 10297 | } finally { |
| 10298 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10299 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 10300 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10301 | |
| 10302 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10303 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 10304 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10306 | mApp, subId, callingPackage, callingFeatureId, |
| 10307 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 10308 | return -1; |
| 10309 | } |
| 10310 | |
| 10311 | final long identity = Binder.clearCallingIdentity(); |
| 10312 | try { |
| 10313 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 10314 | } finally { |
| 10315 | Binder.restoreCallingIdentity(identity); |
| 10316 | } |
| 10317 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10318 | |
| 10319 | @Override |
| 10320 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 10321 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10322 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10323 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10324 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10325 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10326 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaRoamingMode"); |
| 10327 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10328 | final long identity = Binder.clearCallingIdentity(); |
| 10329 | try { |
| 10330 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 10331 | } finally { |
| 10332 | Binder.restoreCallingIdentity(identity); |
| 10333 | } |
| 10334 | } |
| 10335 | |
| 10336 | @Override |
| 10337 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 10338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10339 | mApp, subId, "setCdmaRoamingMode"); |
| 10340 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10341 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10342 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaRoamingMode"); |
| 10343 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10344 | final long identity = Binder.clearCallingIdentity(); |
| 10345 | try { |
| 10346 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 10347 | } finally { |
| 10348 | Binder.restoreCallingIdentity(identity); |
| 10349 | } |
| 10350 | } |
| 10351 | |
| 10352 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10353 | public int getCdmaSubscriptionMode(int subId) { |
| 10354 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10355 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10356 | mApp, subId, "getCdmaSubscriptionMode"); |
| 10357 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10358 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10359 | PackageManager.FEATURE_TELEPHONY_CDMA, "getCdmaSubscriptionMode"); |
| 10360 | |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 10361 | final long identity = Binder.clearCallingIdentity(); |
| 10362 | try { |
| 10363 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 10364 | } finally { |
| 10365 | Binder.restoreCallingIdentity(identity); |
| 10366 | } |
| 10367 | } |
| 10368 | |
| 10369 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10370 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 10371 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10372 | mApp, subId, "setCdmaSubscriptionMode"); |
| 10373 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10374 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10375 | PackageManager.FEATURE_TELEPHONY_CDMA, "setCdmaSubscriptionMode"); |
| 10376 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 10377 | final long identity = Binder.clearCallingIdentity(); |
| 10378 | try { |
| 10379 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 10380 | } finally { |
| 10381 | Binder.restoreCallingIdentity(identity); |
| 10382 | } |
| 10383 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 10384 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10385 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10386 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10387 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10388 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10389 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 10390 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10391 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10392 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10393 | |
| 10394 | enforceTelephonyFeatureWithException(callingPackage, |
| 10395 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberList"); |
| 10396 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10397 | final long identity = Binder.clearCallingIdentity(); |
| 10398 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10399 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 10400 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10401 | if (phone.getEmergencyNumberTracker() != null |
| 10402 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 10403 | emergencyNumberListInternal.put( |
| 10404 | phone.getSubId(), |
| 10405 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 10406 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10407 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10408 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10409 | } finally { |
| 10410 | Binder.restoreCallingIdentity(identity); |
| 10411 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 10412 | } |
| 10413 | |
| 10414 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10415 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 10416 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10417 | if (!exactMatch) { |
| 10418 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10419 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 10420 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10421 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10422 | |
Tomasz Wasilczyk | ef76358 | 2024-09-17 13:50:32 -0700 | [diff] [blame] | 10423 | if (!mApp.getResources().getBoolean( |
| 10424 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 10425 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10426 | PackageManager.FEATURE_TELEPHONY_CALLING, "isEmergencyNumber"); |
| 10427 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10428 | |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10431 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 10432 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 10433 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 10434 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10435 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10436 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 10437 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10438 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 10439 | } |
| 10440 | return false; |
| 10441 | } finally { |
| 10442 | Binder.restoreCallingIdentity(identity); |
| 10443 | } |
| 10444 | } |
| 10445 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10446 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 10447 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 10448 | */ |
| 10449 | @Override |
| 10450 | public void startEmergencyCallbackMode() { |
| 10451 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10452 | "startEmergencyCallbackMode"); |
| 10453 | enforceModifyPermission(); |
| 10454 | final long identity = Binder.clearCallingIdentity(); |
| 10455 | try { |
| 10456 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10457 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 10458 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 10459 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 10460 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 10461 | gsmCdmaPhone.obtainMessage( |
| 10462 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 10463 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 10464 | } |
| 10465 | } |
| 10466 | } finally { |
| 10467 | Binder.restoreCallingIdentity(identity); |
| 10468 | } |
| 10469 | } |
| 10470 | |
| 10471 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 10472 | * Update emergency number list for test mode. |
| 10473 | */ |
| 10474 | @Override |
| 10475 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 10476 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10477 | "updateEmergencyNumberListTestMode"); |
| 10478 | |
| 10479 | final long identity = Binder.clearCallingIdentity(); |
| 10480 | try { |
| 10481 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10482 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10483 | if (tracker != null) { |
| 10484 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 10485 | } |
| 10486 | } |
| 10487 | } finally { |
| 10488 | Binder.restoreCallingIdentity(identity); |
| 10489 | } |
| 10490 | } |
| 10491 | |
| 10492 | /** |
| 10493 | * Get the full emergency number list for test mode. |
| 10494 | */ |
| 10495 | @Override |
| 10496 | public List<String> getEmergencyNumberListTestMode() { |
| 10497 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10498 | "getEmergencyNumberListTestMode"); |
| 10499 | |
| 10500 | final long identity = Binder.clearCallingIdentity(); |
| 10501 | try { |
| 10502 | Set<String> emergencyNumbers = new HashSet<>(); |
| 10503 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10504 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10505 | if (tracker != null) { |
| 10506 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 10507 | emergencyNumbers.add(num.getNumber()); |
| 10508 | } |
| 10509 | } |
| 10510 | } |
| 10511 | return new ArrayList<>(emergencyNumbers); |
| 10512 | } finally { |
| 10513 | Binder.restoreCallingIdentity(identity); |
| 10514 | } |
| 10515 | } |
| 10516 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10517 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10518 | public int getEmergencyNumberDbVersion(int subId) { |
| 10519 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 10520 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10521 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10522 | PackageManager.FEATURE_TELEPHONY_CALLING, "getEmergencyNumberDbVersion"); |
| 10523 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10524 | final long identity = Binder.clearCallingIdentity(); |
| 10525 | try { |
| 10526 | final Phone phone = getPhone(subId); |
| 10527 | if (phone == null) { |
| 10528 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 10529 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 10530 | } |
| 10531 | return phone.getEmergencyNumberDbVersion(); |
| 10532 | } finally { |
| 10533 | Binder.restoreCallingIdentity(identity); |
| 10534 | } |
| 10535 | } |
| 10536 | |
| 10537 | @Override |
| 10538 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 10539 | enforceModifyPermission(); |
| 10540 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10541 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10542 | PackageManager.FEATURE_TELEPHONY_CALLING, "notifyOtaEmergencyNumberDbInstalled"); |
| 10543 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10544 | final long identity = Binder.clearCallingIdentity(); |
| 10545 | try { |
| 10546 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10547 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10548 | if (tracker != null) { |
| 10549 | tracker.updateOtaEmergencyNumberDatabase(); |
| 10550 | } |
| 10551 | } |
| 10552 | } finally { |
| 10553 | Binder.restoreCallingIdentity(identity); |
| 10554 | } |
| 10555 | } |
| 10556 | |
| 10557 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10558 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10559 | enforceActiveEmergencySessionPermission(); |
| 10560 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10561 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10562 | PackageManager.FEATURE_TELEPHONY_CALLING, "updateOtaEmergencyNumberDbFilePath"); |
| 10563 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10564 | final long identity = Binder.clearCallingIdentity(); |
| 10565 | try { |
| 10566 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10567 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10568 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10569 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 10570 | } |
| 10571 | } |
| 10572 | } finally { |
| 10573 | Binder.restoreCallingIdentity(identity); |
| 10574 | } |
| 10575 | } |
| 10576 | |
| 10577 | @Override |
| 10578 | public void resetOtaEmergencyNumberDbFilePath() { |
| 10579 | enforceActiveEmergencySessionPermission(); |
| 10580 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10581 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10582 | PackageManager.FEATURE_TELEPHONY_CALLING, "resetOtaEmergencyNumberDbFilePath"); |
| 10583 | |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 10584 | final long identity = Binder.clearCallingIdentity(); |
| 10585 | try { |
| 10586 | for (Phone phone: PhoneFactory.getPhones()) { |
| 10587 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 10588 | if (tracker != null) { |
| 10589 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 10590 | } |
| 10591 | } |
| 10592 | } finally { |
| 10593 | Binder.restoreCallingIdentity(identity); |
| 10594 | } |
| 10595 | } |
| 10596 | |
| 10597 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 10598 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 10599 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 10600 | Phone phone = getPhone(subId); |
| 10601 | if (phone == null) { |
| 10602 | return null; |
| 10603 | } |
| 10604 | final long identity = Binder.clearCallingIdentity(); |
| 10605 | try { |
| 10606 | UiccProfile profile = UiccController.getInstance() |
| 10607 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 10608 | if (profile != null) { |
| 10609 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 10610 | } |
| 10611 | } finally { |
| 10612 | Binder.restoreCallingIdentity(identity); |
| 10613 | } |
| 10614 | return null; |
| 10615 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10616 | |
| 10617 | /** |
| 10618 | * Enable or disable a modem stack. |
| 10619 | */ |
| 10620 | @Override |
| 10621 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 10622 | enforceModifyPermission(); |
| 10623 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10624 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10625 | PackageManager.FEATURE_TELEPHONY, "enableModemForSlot"); |
| 10626 | |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 10627 | final long identity = Binder.clearCallingIdentity(); |
| 10628 | try { |
| 10629 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10630 | if (phone == null) { |
| 10631 | return false; |
| 10632 | } else { |
| 10633 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 10634 | } |
| 10635 | } finally { |
| 10636 | Binder.restoreCallingIdentity(identity); |
| 10637 | } |
| 10638 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10639 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10640 | /** |
| 10641 | * Whether a modem stack is enabled or not. |
| 10642 | */ |
| 10643 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10644 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 10645 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10646 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 10647 | if (phone == null) return false; |
| 10648 | |
| 10649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10650 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 10651 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10652 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10653 | } |
| 10654 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10655 | enforceTelephonyFeatureWithException(callingPackage, |
| 10656 | PackageManager.FEATURE_TELEPHONY, "isModemEnabledForSlot"); |
| 10657 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10658 | final long identity = Binder.clearCallingIdentity(); |
| 10659 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 10660 | try { |
| 10661 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 10662 | } catch (NoSuchElementException ex) { |
| 10663 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 10664 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 10665 | } finally { |
| 10666 | Binder.restoreCallingIdentity(identity); |
| 10667 | } |
| 10668 | } |
| 10669 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10670 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10671 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10672 | enforceModifyPermission(); |
| 10673 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10674 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10675 | PackageManager.FEATURE_TELEPHONY_CARRIERLOCK, "setMultiSimCarrierRestriction"); |
| 10676 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10677 | final long identity = Binder.clearCallingIdentity(); |
| 10678 | try { |
| 10679 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10680 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10681 | .commit(); |
| 10682 | } finally { |
| 10683 | Binder.restoreCallingIdentity(identity); |
| 10684 | } |
| 10685 | } |
| 10686 | |
| 10687 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10688 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10689 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10690 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10691 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 10692 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10693 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 10694 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10695 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10696 | enforceTelephonyFeatureWithException(callingPackage, |
| 10697 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMultiSimSupported"); |
| 10698 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10699 | final long identity = Binder.clearCallingIdentity(); |
| 10700 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10701 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 10702 | } finally { |
| 10703 | Binder.restoreCallingIdentity(identity); |
| 10704 | } |
| 10705 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10706 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10707 | @TelephonyManager.IsMultiSimSupportedResult |
| 10708 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10709 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 10710 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 10711 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10712 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 10713 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10714 | } |
| 10715 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 10716 | // supported by the modem, indicate that it is restricted. |
| 10717 | PhoneCapability staticCapability = |
| 10718 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 10719 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10720 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 10721 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10722 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10723 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10724 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 10725 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10726 | } |
| 10727 | // Check if support of multiple SIMs is restricted by carrier |
| 10728 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10729 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10730 | } |
| 10731 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10732 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10733 | } |
| 10734 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10735 | /** |
| 10736 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10737 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 10738 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 10739 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10740 | * @param numOfSims number of active sims we want to switch to |
| 10741 | */ |
| 10742 | @Override |
| 10743 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10744 | if (numOfSims == 1) { |
| 10745 | enforceModifyPermission(); |
| 10746 | } else { |
| 10747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10748 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10749 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10750 | |
| 10751 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10752 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "switchMultiSimConfig"); |
| 10753 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10754 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10755 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10756 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10757 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10758 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10759 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10760 | return; |
| 10761 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10762 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10763 | } finally { |
| 10764 | Binder.restoreCallingIdentity(identity); |
| 10765 | } |
| 10766 | } |
| 10767 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10768 | @Override |
| 10769 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10770 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10771 | |
| 10772 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10773 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isApplicationOnUicc"); |
| 10774 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10775 | Phone phone = getPhone(subId); |
| 10776 | if (phone == null) { |
| 10777 | return false; |
| 10778 | } |
| 10779 | final long identity = Binder.clearCallingIdentity(); |
| 10780 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10781 | UiccPort uiccPort = phone.getUiccPort(); |
| 10782 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10783 | return false; |
| 10784 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10785 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10786 | if (uiccProfile == null) { |
| 10787 | return false; |
| 10788 | } |
| 10789 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10790 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10791 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10792 | } |
| 10793 | return false; |
| 10794 | } finally { |
| 10795 | Binder.restoreCallingIdentity(identity); |
| 10796 | } |
| 10797 | } |
| 10798 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10799 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10800 | * Get whether making changes to modem configurations will trigger reboot. |
| 10801 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10802 | */ |
| 10803 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10804 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10805 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10806 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10807 | mApp, subId, callingPackage, callingFeatureId, |
| 10808 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10809 | return false; |
| 10810 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10811 | |
| 10812 | enforceTelephonyFeatureWithException(callingPackage, |
| 10813 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, |
| 10814 | "doesSwitchMultiSimConfigTriggerReboot"); |
| 10815 | |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10816 | final long identity = Binder.clearCallingIdentity(); |
| 10817 | try { |
| 10818 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10819 | } finally { |
| 10820 | Binder.restoreCallingIdentity(identity); |
| 10821 | } |
| 10822 | } |
| 10823 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10824 | private void updateModemStateMetrics() { |
| 10825 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10826 | // TODO: check the state for each modem if the api is ready. |
| 10827 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10828 | } |
| 10829 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10830 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10831 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10832 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10833 | // Verify that the callingPackage belongs to the calling UID |
| 10834 | mApp.getSystemService(AppOpsManager.class) |
| 10835 | .checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10836 | |
| 10837 | enforceTelephonyFeatureWithException(callingPackage, |
| 10838 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSlotsMapping"); |
| 10839 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10840 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10841 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10842 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10843 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10844 | if (slotInfos != null) { |
| 10845 | for (int i = 0; i < slotInfos.length; i++) { |
| 10846 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10847 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10848 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10849 | portInfo.getLogicalSlotIndex())); |
| 10850 | } |
| 10851 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10852 | } |
| 10853 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10854 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10855 | } finally { |
| 10856 | Binder.restoreCallingIdentity(identity); |
| 10857 | } |
| 10858 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10859 | |
| 10860 | /** |
| 10861 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10862 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10863 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10864 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10865 | @Override |
| 10866 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10867 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10868 | } |
| 10869 | |
| 10870 | /** |
| 10871 | * Get the HAL Version of a specific service |
| 10872 | */ |
| 10873 | @Override |
| 10874 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10875 | Phone phone = getDefaultPhone(); |
| 10876 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10877 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10878 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10879 | return hv.major * 100 + hv.minor; |
| 10880 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10881 | |
| 10882 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10883 | * Get the current calling package name. |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10884 | * |
| 10885 | * @return the current calling package name, or null if there is no known package. |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10886 | */ |
| 10887 | @Override |
sangyun | 097dcf7 | 2024-01-04 10:35:49 +0900 | [diff] [blame] | 10888 | public @Nullable String getCurrentPackageName() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10889 | if (mFeatureFlags.hsumPackageManager()) { |
| 10890 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 10891 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10892 | if (pm == null) return null; |
| 10893 | String[] callingUids = pm.getPackagesForUid(Binder.getCallingUid()); |
| 10894 | return (callingUids == null) ? null : callingUids[0]; |
| 10895 | } |
| 10896 | if (mPackageManager == null) return null; |
| 10897 | String[] callingUids = mPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 10898 | return (callingUids == null) ? null : callingUids[0]; |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10899 | } |
| 10900 | |
| 10901 | /** |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10902 | * @return The calling package name or "phone" if the caller is the phone process. This is done |
| 10903 | * because multiple Phone has multiple packages in it and the first element in the array is not |
| 10904 | * actually always the caller. |
| 10905 | * Note: This is for logging purposes only and should not be used for security checks. |
| 10906 | */ |
| 10907 | private String getCurrentPackageNameOrPhone() { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 10908 | PackageManager pm; |
| 10909 | if (mFeatureFlags.hsumPackageManager()) { |
| 10910 | pm = mApp.getBaseContext().createContextAsUser( |
| 10911 | Binder.getCallingUserHandle(), 0).getPackageManager(); |
| 10912 | } else { |
| 10913 | pm = mApp.getPackageManager(); |
| 10914 | } |
Brad Ebinger | 0df4fdf | 2024-07-19 17:26:12 -0700 | [diff] [blame] | 10915 | String uidName = pm == null ? null : pm.getNameForUid(Binder.getCallingUid()); |
| 10916 | if (uidName != null && !uidName.isEmpty()) return uidName; |
| 10917 | return getCurrentPackageName(); |
| 10918 | } |
| 10919 | |
| 10920 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10921 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10922 | * corresponding network requests on a subId. |
| 10923 | * |
| 10924 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10925 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10926 | * 2) APN is un-metered for this subscription, or |
| 10927 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10928 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10929 | * |
| 10930 | * @return whether data is allowed for a apn type. |
| 10931 | * |
| 10932 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10933 | */ |
| 10934 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10935 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10936 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10937 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10938 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10939 | enforceTelephonyFeatureWithException(callingPackage, |
| 10940 | PackageManager.FEATURE_TELEPHONY_DATA, "isDataEnabledForApn"); |
| 10941 | |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10942 | // Now that all security checks passes, perform the operation as ourselves. |
| 10943 | final long identity = Binder.clearCallingIdentity(); |
| 10944 | try { |
| 10945 | Phone phone = getPhone(subId); |
| 10946 | if (phone == null) return false; |
| 10947 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10948 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10949 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10950 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10951 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10952 | phone.getServiceState().getDataRoaming()); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 10953 | isDataEnabled = (phone.getDataSettingsManager() != null) |
| 10954 | ? phone.getDataSettingsManager().isDataEnabled(apnType) : false; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10955 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10956 | } finally { |
| 10957 | Binder.restoreCallingIdentity(identity); |
| 10958 | } |
| 10959 | } |
| 10960 | |
| 10961 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10962 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10963 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10964 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10965 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10966 | PackageManager.FEATURE_TELEPHONY_DATA, "isApnMetered"); |
| 10967 | |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10968 | // Now that all security checks passes, perform the operation as ourselves. |
| 10969 | final long identity = Binder.clearCallingIdentity(); |
| 10970 | try { |
| 10971 | Phone phone = getPhone(subId); |
| 10972 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10973 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10974 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10975 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10976 | } finally { |
| 10977 | Binder.restoreCallingIdentity(identity); |
| 10978 | } |
| 10979 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10980 | |
| 10981 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10982 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10983 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10984 | enforceModifyPermission(); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 10985 | |
| 10986 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 10987 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSystemSelectionChannels"); |
| 10988 | |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10989 | long token = Binder.clearCallingIdentity(); |
| 10990 | try { |
| 10991 | Phone phone = getPhone(subscriptionId); |
| 10992 | if (phone == null) { |
| 10993 | try { |
| 10994 | if (resultCallback != null) { |
| 10995 | resultCallback.accept(false); |
| 10996 | } |
| 10997 | } catch (RemoteException e) { |
| 10998 | // ignore |
| 10999 | } |
| 11000 | return; |
| 11001 | } |
| 11002 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 11003 | Pair.create(specifiers, (x) -> { |
| 11004 | try { |
| 11005 | if (resultCallback != null) { |
| 11006 | resultCallback.accept(x); |
| 11007 | } |
| 11008 | } catch (RemoteException e) { |
| 11009 | // ignore |
| 11010 | } |
| 11011 | }); |
| 11012 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 11013 | } finally { |
| 11014 | Binder.restoreCallingIdentity(token); |
| 11015 | } |
| 11016 | } |
| 11017 | |
| 11018 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11019 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 11020 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 11021 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11022 | mApp, subId, "getSystemSelectionChannels"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11023 | |
| 11024 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11025 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "getSystemSelectionChannels"); |
| 11026 | |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11027 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11028 | final long identity = Binder.clearCallingIdentity(); |
| 11029 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 11030 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 11031 | if (result instanceof IllegalStateException) { |
| 11032 | throw (IllegalStateException) result; |
| 11033 | } |
| 11034 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 11035 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 11036 | return specifiers; |
| 11037 | } finally { |
| 11038 | Binder.restoreCallingIdentity(identity); |
| 11039 | } |
| 11040 | } |
| 11041 | |
| 11042 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11043 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 11044 | enforceReadPrivilegedPermission("isMvnoMatched"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11045 | |
| 11046 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11047 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isMvnoMatched"); |
| 11048 | |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 11049 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 11050 | } |
| 11051 | |
| 11052 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11053 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 11054 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 11055 | if (callingPackage == null) { |
| 11056 | callingPackage = getCurrentPackageName(); |
| 11057 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11058 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 11059 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 11060 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 11061 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11062 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 11063 | } |
| 11064 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 11065 | Intent intent = new Intent(); |
| 11066 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 11067 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 11068 | // Bring up choose default SMS subscription dialog right now |
| 11069 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 11070 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11071 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 11072 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11073 | |
| 11074 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11075 | public void showSwitchToManagedProfileDialog() { |
| 11076 | enforceModifyPermission(); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11077 | try { |
| 11078 | // Note: This intent is constructed to ensure that the IntentForwarderActivity is |
| 11079 | // shown in accordance with the intent filters in DefaultCrossProfileIntentFilterUtils |
| 11080 | // for work telephony. |
| 11081 | Intent intent = new Intent(Intent.ACTION_SENDTO); |
| 11082 | intent.setData(Uri.parse("smsto:")); |
| 11083 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11084 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11085 | } catch (ActivityNotFoundException e) { |
| 11086 | Log.w(LOG_TAG, "Unable to show intent forwarder, try showing error dialog instead"); |
| 11087 | Intent intent = new Intent(); |
| 11088 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 11089 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 11090 | mApp.startActivityAsUser(intent, UserHandle.CURRENT); |
Anthony Alridge | 70ba557 | 2023-05-02 12:14:14 +0000 | [diff] [blame] | 11091 | } |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 11092 | } |
| 11093 | |
| 11094 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11095 | public String getMmsUAProfUrl(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11096 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11097 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUAProfUrl"); |
| 11098 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11099 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11100 | final long identity = Binder.clearCallingIdentity(); |
| 11101 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11102 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 11103 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 11104 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 11105 | return carrierUAProfUrl; |
| 11106 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11107 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11108 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11109 | } finally { |
| 11110 | Binder.restoreCallingIdentity(identity); |
| 11111 | } |
| 11112 | } |
| 11113 | |
| 11114 | @Override |
| 11115 | public String getMmsUserAgent(int subId) { |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11116 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11117 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getMmsUserAgent"); |
| 11118 | |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11119 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 11120 | final long identity = Binder.clearCallingIdentity(); |
| 11121 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 11122 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 11123 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 11124 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 11125 | return carrierUserAgent; |
| 11126 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 11127 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 11128 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 11129 | } finally { |
| 11130 | Binder.restoreCallingIdentity(identity); |
| 11131 | } |
| 11132 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11133 | |
| 11134 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11135 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 11136 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11137 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11138 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11139 | PackageManager.FEATURE_TELEPHONY_DATA, "isMobileDataPolicyEnabled"); |
| 11140 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11141 | final long identity = Binder.clearCallingIdentity(); |
| 11142 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11143 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11144 | if (phone == null || phone.getDataSettingsManager() == null) return false; |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11145 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11146 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 11147 | } finally { |
| 11148 | Binder.restoreCallingIdentity(identity); |
| 11149 | } |
| 11150 | } |
| 11151 | |
| 11152 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 11153 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11154 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11155 | enforceModifyPermission(); |
| 11156 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11157 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11158 | PackageManager.FEATURE_TELEPHONY_DATA, "setMobileDataPolicyEnabled"); |
| 11159 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11160 | final long identity = Binder.clearCallingIdentity(); |
| 11161 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 11162 | Phone phone = getPhone(subscriptionId); |
Hunsuk Choi | bf761bf | 2024-06-18 08:34:32 +0000 | [diff] [blame] | 11163 | if (phone == null || phone.getDataSettingsManager() == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11164 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 11165 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 11166 | } finally { |
| 11167 | Binder.restoreCallingIdentity(identity); |
| 11168 | } |
| 11169 | } |
| 11170 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11171 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 11172 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 11173 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 11174 | * otherwise. |
| 11175 | */ |
| 11176 | @Override |
| 11177 | public void setCepEnabled(boolean isCepEnabled) { |
| 11178 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 11179 | |
| 11180 | final long identity = Binder.clearCallingIdentity(); |
| 11181 | try { |
| 11182 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 11183 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11184 | Phone defaultPhone = phone.getImsPhone(); |
| 11185 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 11186 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 11187 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11188 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 11189 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 11190 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 11191 | + imsPhone.getMsisdn()); |
| 11192 | } |
| 11193 | } |
| 11194 | } finally { |
| 11195 | Binder.restoreCallingIdentity(identity); |
| 11196 | } |
| 11197 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11198 | |
| 11199 | /** |
| 11200 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 11201 | * |
| 11202 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 11203 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 11204 | * before being read. |
| 11205 | */ |
| 11206 | @Override |
| 11207 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 11208 | isCompressed) { |
| 11209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11210 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11211 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11212 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11213 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11214 | |
| 11215 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11216 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11217 | Binder.getCallingUserHandle())) { |
| 11218 | if (!isImsAvailableOnDevice()) { |
| 11219 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11220 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11221 | throw new IllegalStateException("IMS not available on device."); |
| 11222 | } |
| 11223 | } else { |
| 11224 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11225 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11226 | "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11227 | } |
| 11228 | |
| 11229 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11230 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11231 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 11232 | } finally { |
| 11233 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 11234 | } |
| 11235 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11236 | |
| 11237 | @Override |
| 11238 | public boolean isIccLockEnabled(int subId) { |
| 11239 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 11240 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11241 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11242 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "isIccLockEnabled"); |
| 11243 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11244 | // Now that all security checks passes, perform the operation as ourselves. |
| 11245 | final long identity = Binder.clearCallingIdentity(); |
| 11246 | try { |
| 11247 | Phone phone = getPhone(subId); |
| 11248 | if (phone != null && phone.getIccCard() != null) { |
| 11249 | return phone.getIccCard().getIccLockEnabled(); |
| 11250 | } else { |
| 11251 | return false; |
| 11252 | } |
| 11253 | } finally { |
| 11254 | Binder.restoreCallingIdentity(identity); |
| 11255 | } |
| 11256 | } |
| 11257 | |
| 11258 | /** |
| 11259 | * Set the ICC pin lock enabled or disabled. |
| 11260 | * |
| 11261 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 11262 | * three cases: |
| 11263 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 11264 | * successfully. |
| 11265 | * - Positive number and zero for remaining password attempts. |
| 11266 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11267 | * |
| 11268 | */ |
| 11269 | @Override |
| 11270 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 11271 | enforceModifyPermission(); |
| 11272 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11273 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11274 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "setIccLockEnabled"); |
| 11275 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11276 | Phone phone = getPhone(subId); |
| 11277 | if (phone == null) { |
| 11278 | return 0; |
| 11279 | } |
| 11280 | // Now that all security checks passes, perform the operation as ourselves. |
| 11281 | final long identity = Binder.clearCallingIdentity(); |
| 11282 | try { |
| 11283 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 11284 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 11285 | return attemptsRemaining; |
| 11286 | |
| 11287 | } catch (Exception e) { |
| 11288 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 11289 | } finally { |
| 11290 | Binder.restoreCallingIdentity(identity); |
| 11291 | } |
| 11292 | return 0; |
| 11293 | } |
| 11294 | |
| 11295 | /** |
| 11296 | * Change the ICC password used in ICC pin lock. |
| 11297 | * |
| 11298 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 11299 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 11300 | * - Positive number and zero for remaining password attempts. |
| 11301 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 11302 | * |
| 11303 | */ |
| 11304 | @Override |
| 11305 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 11306 | enforceModifyPermission(); |
| 11307 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11308 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11309 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "changeIccLockPassword"); |
| 11310 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 11311 | Phone phone = getPhone(subId); |
| 11312 | if (phone == null) { |
| 11313 | return 0; |
| 11314 | } |
| 11315 | // Now that all security checks passes, perform the operation as ourselves. |
| 11316 | final long identity = Binder.clearCallingIdentity(); |
| 11317 | try { |
| 11318 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 11319 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 11320 | return attemptsRemaining; |
| 11321 | |
| 11322 | } catch (Exception e) { |
| 11323 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 11324 | } finally { |
| 11325 | Binder.restoreCallingIdentity(identity); |
| 11326 | } |
| 11327 | return 0; |
| 11328 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11329 | |
| 11330 | /** |
| 11331 | * Request for receiving user activity notification |
| 11332 | */ |
| 11333 | @Override |
| 11334 | public void requestUserActivityNotification() { |
| 11335 | if (!mNotifyUserActivity.get() |
| 11336 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 11337 | mNotifyUserActivity.set(true); |
| 11338 | } |
| 11339 | } |
| 11340 | |
| 11341 | /** |
| 11342 | * Called when userActivity is signalled in the power manager. |
| 11343 | * This is safe to call from any thread, with any window manager locks held or not. |
| 11344 | */ |
| 11345 | @Override |
| 11346 | public void userActivity() { |
| 11347 | // *************************************** |
| 11348 | // * Inherited from PhoneWindowManager * |
| 11349 | // *************************************** |
| 11350 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 11351 | // WITH ITS LOCKS HELD. |
| 11352 | // |
| 11353 | // This code must be VERY careful about the locks |
| 11354 | // it acquires. |
| 11355 | // In fact, the current code acquires way too many, |
| 11356 | // and probably has lurking deadlocks. |
| 11357 | |
Jack Yu | 8637449 | 2024-09-16 13:05:44 -0700 | [diff] [blame] | 11358 | if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 11359 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 11360 | } |
| 11361 | |
| 11362 | if (mNotifyUserActivity.getAndSet(false)) { |
| 11363 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 11364 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 11365 | } |
| 11366 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 11367 | |
| 11368 | @Override |
| 11369 | public boolean canConnectTo5GInDsdsMode() { |
| 11370 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 11371 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11372 | |
| 11373 | @Override |
| 11374 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 11375 | String callingFeatureId) { |
| 11376 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 11377 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 11378 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 11379 | } |
| 11380 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11381 | enforceTelephonyFeatureWithException(callingPackage, |
| 11382 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getEquivalentHomePlmns"); |
| 11383 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 11384 | Phone phone = getPhone(subId); |
| 11385 | if (phone == null) { |
| 11386 | throw new RuntimeException("phone is not available"); |
| 11387 | } |
| 11388 | // Now that all security checks passes, perform the operation as ourselves. |
| 11389 | final long identity = Binder.clearCallingIdentity(); |
| 11390 | try { |
| 11391 | return phone.getEquivalentHomePlmns(); |
| 11392 | } finally { |
| 11393 | Binder.restoreCallingIdentity(identity); |
| 11394 | } |
| 11395 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11396 | |
| 11397 | @Override |
| 11398 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11399 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 11400 | if (!mApp.getResources().getBoolean( |
| 11401 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 11402 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11403 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 11404 | "isRadioInterfaceCapabilitySupported"); |
| 11405 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11406 | |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11407 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 11408 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11409 | if (radioInterfaceCapabilities == null) { |
| 11410 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11411 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 11412 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 11413 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11414 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11415 | @Override |
| 11416 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 11417 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11418 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 11419 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11420 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 11421 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11422 | Manifest.permission.MODIFY_PHONE_STATE); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11423 | |
| 11424 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11425 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "bootstrapAuthenticationRequest"); |
| 11426 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11427 | if (DBG) { |
| 11428 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 11429 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 11430 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 11431 | } |
| 11432 | |
| 11433 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 11434 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 11435 | || appType > TelephonyManager.APPTYPE_ISIM |
| 11436 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 11437 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 11438 | if (callback != null) { |
| 11439 | try { |
| 11440 | callback.onAuthenticationFailure( |
| 11441 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 11442 | } catch (RemoteException exception) { |
| 11443 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 11444 | } |
| 11445 | return; |
| 11446 | } |
| 11447 | } |
| 11448 | |
| 11449 | final long token = Binder.clearCallingIdentity(); |
| 11450 | try { |
| 11451 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 11452 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11453 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11454 | } finally { |
| 11455 | Binder.restoreCallingIdentity(token); |
| 11456 | } |
| 11457 | } |
| 11458 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11459 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11460 | * Attempts to set the radio power state for all phones for thermal reason. |
| 11461 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11462 | * requested radio power state will actually be set. See {@link |
| 11463 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 11464 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11465 | * @param enable {@code true} if trying to turn radio on. |
| 11466 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 11467 | * false}. |
| 11468 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11469 | private boolean setRadioPowerForThermal(boolean enable) { |
| 11470 | boolean isPhoneAvailable = false; |
| 11471 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 11472 | Phone phone = PhoneFactory.getPhone(i); |
| 11473 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 11474 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11475 | isPhoneAvailable = true; |
| 11476 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11477 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11478 | |
| 11479 | // return true if successfully informed the phone object about the thermal radio power |
| 11480 | // request. |
| 11481 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11482 | } |
| 11483 | |
| 11484 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11485 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11486 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 11487 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 11488 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 11489 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 11490 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 11491 | } |
| 11492 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11493 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 11494 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11495 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11496 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11497 | } |
| 11498 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11499 | setDataEnabledForReason( |
| 11500 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11501 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11502 | if (isDataThrottlingSupported) { |
| 11503 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11504 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11505 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 11506 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 11507 | } else if (thermalMitigationResult |
| 11508 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 11509 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 11510 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 11511 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11512 | } |
| 11513 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11514 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 11515 | |
| 11516 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11517 | } |
| 11518 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11519 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 11520 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 11521 | for (String pckg : context.getResources() |
| 11522 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 11523 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 11524 | } |
| 11525 | } |
| 11526 | |
| 11527 | return sThermalMitigationAllowlistedPackages; |
| 11528 | } |
| 11529 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11530 | private boolean isAnyPhoneInEmergencyState() { |
| 11531 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 11532 | if (tm.isInEmergencyCall()) { |
| 11533 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 11534 | return true; |
| 11535 | } |
| 11536 | for (Phone phone : PhoneFactory.getPhones()) { |
| 11537 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 11538 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11539 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 11540 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11541 | return true; |
| 11542 | } |
| 11543 | } |
| 11544 | |
| 11545 | return false; |
| 11546 | } |
| 11547 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11548 | /** |
| 11549 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 11550 | * @param packageName name of package to be allowlisted |
| 11551 | * @param context |
| 11552 | */ |
| 11553 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 11554 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11555 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 11556 | } |
| 11557 | |
| 11558 | /** |
| 11559 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 11560 | * @param packageName name of package to remove from allowlist |
| 11561 | * @param context |
| 11562 | */ |
| 11563 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 11564 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 11565 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 11566 | } |
| 11567 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11568 | /** |
| 11569 | * Thermal mitigation request to control functionalities at modem. |
| 11570 | * |
| 11571 | * @param subId the id of the subscription. |
| 11572 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11573 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11574 | * |
| 11575 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 11576 | */ |
| 11577 | @Override |
| 11578 | @ThermalMitigationResult |
| 11579 | public int sendThermalMitigationRequest( |
| 11580 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11581 | ThermalMitigationRequest thermalMitigationRequest, |
| 11582 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11583 | enforceModifyPermission(); |
| 11584 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11585 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11586 | |
| 11587 | enforceTelephonyFeatureWithException(callingPackage, |
| 11588 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "sendThermalMitigationRequest"); |
| 11589 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 11590 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 11591 | .contains(callingPackage)) { |
| 11592 | throw new SecurityException("Calling package must be configured in the device config. " |
| 11593 | + "calling package: " + callingPackage); |
| 11594 | } |
| 11595 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11596 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 11597 | final long identity = Binder.clearCallingIdentity(); |
| 11598 | |
| 11599 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 11600 | try { |
| 11601 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 11602 | switch (thermalMitigationAction) { |
| 11603 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 11604 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11605 | handleDataThrottlingRequest(subId, |
| 11606 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 11607 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11608 | break; |
| 11609 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 11610 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11611 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 11612 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 11613 | } |
| 11614 | |
| 11615 | // Ensure that radio is on. If not able to power on due to phone being |
| 11616 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11617 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11618 | thermalMitigationResult = |
| 11619 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11620 | break; |
| 11621 | } |
| 11622 | |
| 11623 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 11624 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11625 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 11626 | break; |
| 11627 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 11628 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 11629 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 11630 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 11631 | } |
| 11632 | |
| 11633 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 11634 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11635 | Phone phone = getPhone(subId); |
| 11636 | if (phone == null) { |
| 11637 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11638 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11639 | break; |
| 11640 | } |
| 11641 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11642 | TelephonyConnectionService service = |
| 11643 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 11644 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 11645 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 11646 | thermalMitigationResult = |
| 11647 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 11648 | break; |
| 11649 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11650 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11651 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11652 | break; |
| 11653 | } |
| 11654 | } else { |
| 11655 | thermalMitigationResult = |
| 11656 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11657 | break; |
| 11658 | } |
| 11659 | |
| 11660 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 11661 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 11662 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11663 | thermalMitigationResult = |
| 11664 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 11665 | break; |
| 11666 | } |
| 11667 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11668 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 11669 | break; |
| 11670 | default: |
| 11671 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 11672 | + "not exist. Requested action: " + thermalMitigationAction); |
| 11673 | } |
| 11674 | } catch (IllegalArgumentException e) { |
| 11675 | throw e; |
| 11676 | } catch (Exception e) { |
| 11677 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 11678 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 11679 | } finally { |
| 11680 | Binder.restoreCallingIdentity(identity); |
| 11681 | } |
| 11682 | |
| 11683 | if (DBG) { |
| 11684 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 11685 | + thermalMitigationResult); |
| 11686 | } |
| 11687 | |
| 11688 | return thermalMitigationResult; |
| 11689 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11690 | |
| 11691 | /** |
| 11692 | * Set the GbaService Package Name that Telephony will bind to. |
| 11693 | * |
| 11694 | * @param subId The sim that the GbaService is associated with. |
| 11695 | * @param packageName The name of the package to be replaced with. |
| 11696 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11697 | */ |
| 11698 | @Override |
| 11699 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 11700 | enforceModifyPermission(); |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11701 | int userId = ActivityManager.getCurrentUser(); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11702 | final long identity = Binder.clearCallingIdentity(); |
| 11703 | try { |
Jack Yu | 02533f1 | 2024-10-03 18:44:32 -0700 | [diff] [blame] | 11704 | return getGbaManager(subId).overrideServicePackage(packageName, userId); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 11705 | } finally { |
| 11706 | Binder.restoreCallingIdentity(identity); |
| 11707 | } |
| 11708 | } |
| 11709 | |
| 11710 | /** |
| 11711 | * Return the package name of the currently bound GbaService. |
| 11712 | * |
| 11713 | * @param subId The sim that the GbaService is associated with. |
| 11714 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 11715 | */ |
| 11716 | @Override |
| 11717 | public String getBoundGbaService(int subId) { |
| 11718 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 11719 | |
| 11720 | final long identity = Binder.clearCallingIdentity(); |
| 11721 | try { |
| 11722 | return getGbaManager(subId).getServicePackage(); |
| 11723 | } finally { |
| 11724 | Binder.restoreCallingIdentity(identity); |
| 11725 | } |
| 11726 | } |
| 11727 | |
| 11728 | /** |
| 11729 | * Set the release time for telephony to unbind GbaService. |
| 11730 | * |
| 11731 | * @param subId The sim that the GbaService is associated with. |
| 11732 | * @param interval The release time to unbind GbaService by millisecond. |
| 11733 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 11734 | */ |
| 11735 | @Override |
| 11736 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 11737 | enforceModifyPermission(); |
| 11738 | |
| 11739 | final long identity = Binder.clearCallingIdentity(); |
| 11740 | try { |
| 11741 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 11742 | } finally { |
| 11743 | Binder.restoreCallingIdentity(identity); |
| 11744 | } |
| 11745 | } |
| 11746 | |
| 11747 | /** |
| 11748 | * Return the release time for telephony to unbind GbaService. |
| 11749 | * |
| 11750 | * @param subId The sim that the GbaService is associated with. |
| 11751 | * @return The release time to unbind GbaService by millisecond. |
| 11752 | */ |
| 11753 | @Override |
| 11754 | public int getGbaReleaseTime(int subId) { |
| 11755 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 11756 | |
| 11757 | final long identity = Binder.clearCallingIdentity(); |
| 11758 | try { |
| 11759 | return getGbaManager(subId).getReleaseTime(); |
| 11760 | } finally { |
| 11761 | Binder.restoreCallingIdentity(identity); |
| 11762 | } |
| 11763 | } |
| 11764 | |
| 11765 | private GbaManager getGbaManager(int subId) { |
| 11766 | GbaManager instance = GbaManager.getInstance(subId); |
| 11767 | if (instance == null) { |
| 11768 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 11769 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 11770 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 11771 | } |
| 11772 | return instance; |
| 11773 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11774 | |
| 11775 | /** |
| 11776 | * indicate whether the device and the carrier can support |
| 11777 | * RCS VoLTE single registration. |
| 11778 | */ |
| 11779 | @Override |
| 11780 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11781 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11782 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 11783 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11784 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11785 | |
| 11786 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11787 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11788 | } |
| 11789 | |
| 11790 | final long identity = Binder.clearCallingIdentity(); |
| 11791 | try { |
| 11792 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 11793 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11794 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 11795 | if (isCapable != null) { |
| 11796 | return isCapable; |
| 11797 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11798 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 11799 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11800 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11801 | } finally { |
| 11802 | Binder.restoreCallingIdentity(identity); |
| 11803 | } |
| 11804 | } |
| 11805 | |
| 11806 | /** |
| 11807 | * Register RCS provisioning callback. |
| 11808 | */ |
| 11809 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11810 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11811 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11812 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11813 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11814 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11815 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11816 | |
| 11817 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11818 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11819 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11820 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11821 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11822 | Binder.getCallingUserHandle())) { |
| 11823 | if (!isImsAvailableOnDevice()) { |
| 11824 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11825 | "IMS not available on device."); |
| 11826 | } |
| 11827 | } else { |
| 11828 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11829 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "registerRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11830 | } |
| 11831 | |
| 11832 | final long identity = Binder.clearCallingIdentity(); |
| 11833 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11834 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11835 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11836 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11837 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11838 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11839 | } finally { |
| 11840 | Binder.restoreCallingIdentity(identity); |
| 11841 | } |
| 11842 | } |
| 11843 | |
| 11844 | /** |
| 11845 | * Unregister RCS provisioning callback. |
| 11846 | */ |
| 11847 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11848 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11849 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11850 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11851 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11852 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 11853 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11854 | |
| 11855 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11856 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11857 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11858 | |
| 11859 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11860 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11861 | Binder.getCallingUserHandle())) { |
| 11862 | if (!isImsAvailableOnDevice()) { |
| 11863 | // operation failed silently |
| 11864 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 11865 | return; |
| 11866 | } |
| 11867 | } else { |
| 11868 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11869 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, |
| 11870 | "unregisterRcsProvisioningCallback"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11871 | } |
| 11872 | |
| 11873 | final long identity = Binder.clearCallingIdentity(); |
| 11874 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 11875 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 11876 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11877 | } finally { |
| 11878 | Binder.restoreCallingIdentity(identity); |
| 11879 | } |
| 11880 | } |
| 11881 | |
| 11882 | /** |
| 11883 | * trigger RCS reconfiguration. |
| 11884 | */ |
| 11885 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11886 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11887 | "triggerRcsReconfiguration", |
| 11888 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11889 | |
| 11890 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11891 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11892 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11893 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11894 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11895 | Binder.getCallingUserHandle())) { |
| 11896 | if (!isImsAvailableOnDevice()) { |
| 11897 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11898 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11899 | throw new IllegalStateException("IMS not available on device."); |
| 11900 | } |
| 11901 | } else { |
| 11902 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11903 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "triggerRcsReconfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11904 | } |
| 11905 | |
| 11906 | final long identity = Binder.clearCallingIdentity(); |
| 11907 | try { |
| 11908 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11909 | } finally { |
| 11910 | Binder.restoreCallingIdentity(identity); |
| 11911 | } |
| 11912 | } |
| 11913 | |
| 11914 | /** |
| 11915 | * Provide the client configuration parameters of the RCS application. |
| 11916 | */ |
| 11917 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11918 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11919 | "setRcsClientConfiguration", |
| 11920 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11921 | |
| 11922 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11923 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11924 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 11925 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 11926 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, getCurrentPackageName(), |
| 11927 | Binder.getCallingUserHandle())) { |
| 11928 | if (!isImsAvailableOnDevice()) { |
| 11929 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11930 | "IMS not available on device."); |
| 11931 | } |
| 11932 | } else { |
| 11933 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 11934 | FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION, "setRcsClientConfiguration"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11935 | } |
| 11936 | |
| 11937 | final long identity = Binder.clearCallingIdentity(); |
| 11938 | |
| 11939 | try { |
| 11940 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11941 | if (configBinder == null) { |
| 11942 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11943 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11944 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11945 | } else { |
| 11946 | configBinder.setRcsClientConfiguration(rcc); |
| 11947 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11948 | |
| 11949 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11950 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11951 | } catch (RemoteException e) { |
| 11952 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11953 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11954 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11955 | } finally { |
| 11956 | Binder.restoreCallingIdentity(identity); |
| 11957 | } |
| 11958 | } |
| 11959 | |
| 11960 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11961 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11962 | */ |
| 11963 | @Override |
| 11964 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11965 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11966 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11967 | |
| 11968 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11969 | } |
| 11970 | |
| 11971 | /** |
| 11972 | * Gets the test mode for RCS VoLTE single registration. |
| 11973 | */ |
| 11974 | @Override |
| 11975 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11976 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11977 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11978 | |
| 11979 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11980 | } |
| 11981 | |
| 11982 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11983 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11984 | */ |
| 11985 | @Override |
| 11986 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11987 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11988 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11989 | enforceModifyPermission(); |
| 11990 | |
| 11991 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11992 | : Boolean.parseBoolean(enabledStr); |
| 11993 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11994 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11995 | } |
| 11996 | |
| 11997 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11998 | * Sends a device to device communication message. Only usable via shell. |
| 11999 | * @param message message to send. |
| 12000 | * @param value message value. |
| 12001 | */ |
| 12002 | @Override |
| 12003 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 12004 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12005 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12006 | enforceModifyPermission(); |
| 12007 | |
| 12008 | final long identity = Binder.clearCallingIdentity(); |
| 12009 | try { |
| 12010 | TelephonyConnectionService service = |
| 12011 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12012 | if (service == null) { |
| 12013 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 12014 | return; |
| 12015 | } |
| 12016 | service.sendTestDeviceToDeviceMessage(message, value); |
| 12017 | } finally { |
| 12018 | Binder.restoreCallingIdentity(identity); |
| 12019 | } |
| 12020 | } |
| 12021 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 12022 | /** |
| 12023 | * Sets the specified device to device transport active. |
| 12024 | * @param transport The transport to set active. |
| 12025 | */ |
| 12026 | @Override |
| 12027 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 12028 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12029 | "setActiveDeviceToDeviceTransport"); |
| 12030 | enforceModifyPermission(); |
| 12031 | |
| 12032 | final long identity = Binder.clearCallingIdentity(); |
| 12033 | try { |
| 12034 | TelephonyConnectionService service = |
| 12035 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 12036 | if (service == null) { |
| 12037 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 12038 | return; |
| 12039 | } |
| 12040 | service.setActiveDeviceToDeviceTransport(transport); |
| 12041 | } finally { |
| 12042 | Binder.restoreCallingIdentity(identity); |
| 12043 | } |
| 12044 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12045 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 12046 | @Override |
| 12047 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 12048 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12049 | "setDeviceToDeviceForceEnabled"); |
| 12050 | |
| 12051 | final long identity = Binder.clearCallingIdentity(); |
| 12052 | try { |
| 12053 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 12054 | p -> { |
| 12055 | Phone thePhone = p.getImsPhone(); |
| 12056 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 12057 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 12058 | CallTracker tracker = imsPhone.getCallTracker(); |
| 12059 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 12060 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 12061 | (ImsPhoneCallTracker) tracker; |
| 12062 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 12063 | } |
| 12064 | } |
| 12065 | } |
| 12066 | ); |
| 12067 | } finally { |
| 12068 | Binder.restoreCallingIdentity(identity); |
| 12069 | } |
| 12070 | } |
| 12071 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 12072 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 12073 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 12074 | */ |
| 12075 | @Override |
| 12076 | public boolean getDeviceSingleRegistrationEnabled() { |
| 12077 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 12078 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 12079 | } |
| 12080 | |
| 12081 | /** |
| 12082 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12083 | */ |
| 12084 | @Override |
| 12085 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 12086 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12087 | "setCarrierSingleRegistrationEnabledOverride"); |
| 12088 | enforceModifyPermission(); |
| 12089 | |
| 12090 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12091 | : Boolean.parseBoolean(enabledStr); |
| 12092 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 12093 | subId, enabled); |
| 12094 | } |
| 12095 | |
| 12096 | /** |
| 12097 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 12098 | */ |
| 12099 | @Override |
| 12100 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 12101 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 12102 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 12103 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12104 | |
| 12105 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 12106 | * Overrides the ims feature validation result |
| 12107 | */ |
| 12108 | @Override |
| 12109 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 12110 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12111 | "setImsFeatureValidationOverride"); |
| 12112 | |
| 12113 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 12114 | : Boolean.parseBoolean(enabledStr); |
| 12115 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 12116 | subId, enabled); |
| 12117 | } |
| 12118 | |
| 12119 | /** |
| 12120 | * Gets the ims feature validation override value |
| 12121 | */ |
| 12122 | @Override |
| 12123 | public boolean getImsFeatureValidationOverride(int subId) { |
| 12124 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12125 | "getImsFeatureValidationOverride"); |
| 12126 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 12127 | } |
| 12128 | |
| 12129 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 12130 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 12131 | * their mobile plan. |
| 12132 | */ |
| 12133 | @Override |
| 12134 | public String getMobileProvisioningUrl() { |
| 12135 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 12136 | final long identity = Binder.clearCallingIdentity(); |
| 12137 | try { |
| 12138 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 12139 | } finally { |
| 12140 | Binder.restoreCallingIdentity(identity); |
| 12141 | } |
| 12142 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12143 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12144 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 12145 | * Get the EAB contact from the EAB database. |
| 12146 | */ |
| 12147 | @Override |
| 12148 | public String getContactFromEab(String contact) { |
| 12149 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 12150 | enforceModifyPermission(); |
| 12151 | final long identity = Binder.clearCallingIdentity(); |
| 12152 | try { |
| 12153 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 12154 | } finally { |
| 12155 | Binder.restoreCallingIdentity(identity); |
| 12156 | } |
| 12157 | } |
| 12158 | |
| 12159 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 12160 | * Get the EAB capability from the EAB database. |
| 12161 | */ |
| 12162 | @Override |
| 12163 | public String getCapabilityFromEab(String contact) { |
| 12164 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 12165 | enforceModifyPermission(); |
| 12166 | final long identity = Binder.clearCallingIdentity(); |
| 12167 | try { |
| 12168 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 12169 | } finally { |
| 12170 | Binder.restoreCallingIdentity(identity); |
| 12171 | } |
| 12172 | } |
| 12173 | |
| 12174 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 12175 | * Remove the EAB contacts from the EAB database. |
| 12176 | */ |
| 12177 | @Override |
| 12178 | public int removeContactFromEab(int subId, String contacts) { |
| 12179 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 12180 | enforceModifyPermission(); |
| 12181 | final long identity = Binder.clearCallingIdentity(); |
| 12182 | try { |
| 12183 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 12184 | } finally { |
| 12185 | Binder.restoreCallingIdentity(identity); |
| 12186 | } |
| 12187 | } |
| 12188 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12189 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12190 | public boolean getDeviceUceEnabled() { |
| 12191 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 12192 | final long identity = Binder.clearCallingIdentity(); |
| 12193 | try { |
| 12194 | return mApp.getDeviceUceEnabled(); |
| 12195 | } finally { |
| 12196 | Binder.restoreCallingIdentity(identity); |
| 12197 | } |
| 12198 | } |
| 12199 | |
| 12200 | @Override |
| 12201 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 12202 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 12203 | final long identity = Binder.clearCallingIdentity(); |
| 12204 | try { |
| 12205 | mApp.setDeviceUceEnabled(isEnabled); |
| 12206 | } finally { |
| 12207 | Binder.restoreCallingIdentity(identity); |
| 12208 | } |
| 12209 | } |
| 12210 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12211 | /** |
| 12212 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12213 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12214 | */ |
| 12215 | // Used for SHELL command only right now. |
| 12216 | @Override |
| 12217 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 12218 | List<String> featureTags) { |
| 12219 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12220 | "addUceRegistrationOverrideShell"); |
| 12221 | final long identity = Binder.clearCallingIdentity(); |
| 12222 | try { |
| 12223 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 12224 | new ArraySet<>(featureTags)); |
| 12225 | } catch (ImsException e) { |
| 12226 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12227 | } finally { |
| 12228 | Binder.restoreCallingIdentity(identity); |
| 12229 | } |
| 12230 | } |
| 12231 | |
| 12232 | /** |
| 12233 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 12234 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12235 | */ |
| 12236 | // Used for SHELL command only right now. |
| 12237 | @Override |
| 12238 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 12239 | List<String> featureTags) { |
| 12240 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12241 | "removeUceRegistrationOverrideShell"); |
| 12242 | final long identity = Binder.clearCallingIdentity(); |
| 12243 | try { |
| 12244 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 12245 | new ArraySet<>(featureTags)); |
| 12246 | } catch (ImsException e) { |
| 12247 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12248 | } finally { |
| 12249 | Binder.restoreCallingIdentity(identity); |
| 12250 | } |
| 12251 | } |
| 12252 | |
| 12253 | /** |
| 12254 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 12255 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12256 | */ |
| 12257 | // Used for SHELL command only right now. |
| 12258 | @Override |
| 12259 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 12260 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12261 | "clearUceRegistrationOverrideShell"); |
| 12262 | final long identity = Binder.clearCallingIdentity(); |
| 12263 | try { |
| 12264 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 12265 | } catch (ImsException e) { |
| 12266 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12267 | } finally { |
| 12268 | Binder.restoreCallingIdentity(identity); |
| 12269 | } |
| 12270 | } |
| 12271 | |
| 12272 | /** |
| 12273 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 12274 | */ |
| 12275 | // Used for SHELL command only right now. |
| 12276 | @Override |
| 12277 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 12278 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 12279 | "getLatestRcsContactUceCapabilityShell"); |
| 12280 | final long identity = Binder.clearCallingIdentity(); |
| 12281 | try { |
| 12282 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 12283 | } catch (ImsException e) { |
| 12284 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12285 | } finally { |
| 12286 | Binder.restoreCallingIdentity(identity); |
| 12287 | } |
| 12288 | } |
| 12289 | |
| 12290 | /** |
| 12291 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 12292 | * device does not have an active PUBLISH. |
| 12293 | */ |
| 12294 | // Used for SHELL command only right now. |
| 12295 | @Override |
| 12296 | public String getLastUcePidfXmlShell(int subId) { |
| 12297 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 12298 | final long identity = Binder.clearCallingIdentity(); |
| 12299 | try { |
| 12300 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 12301 | } catch (ImsException e) { |
| 12302 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12303 | } finally { |
| 12304 | Binder.restoreCallingIdentity(identity); |
| 12305 | } |
| 12306 | } |
| 12307 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 12308 | /** |
| 12309 | * Remove UCE requests cannot be sent to the network status. |
| 12310 | */ |
| 12311 | // Used for SHELL command only right now. |
| 12312 | @Override |
| 12313 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 12314 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 12315 | final long identity = Binder.clearCallingIdentity(); |
| 12316 | try { |
| 12317 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 12318 | } catch (ImsException e) { |
| 12319 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12320 | } finally { |
| 12321 | Binder.restoreCallingIdentity(identity); |
| 12322 | } |
| 12323 | } |
| 12324 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 12325 | /** |
| 12326 | * Remove UCE requests cannot be sent to the network status. |
| 12327 | */ |
| 12328 | // Used for SHELL command only. |
| 12329 | @Override |
| 12330 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 12331 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 12332 | final long identity = Binder.clearCallingIdentity(); |
| 12333 | try { |
| 12334 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 12335 | } catch (ImsException e) { |
| 12336 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 12337 | } finally { |
| 12338 | Binder.restoreCallingIdentity(identity); |
| 12339 | } |
| 12340 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 12341 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 12342 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12343 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12344 | String callingPackage) { |
| 12345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12346 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 12347 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12348 | enforceTelephonyFeatureWithException(callingPackage, |
| 12349 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "setSignalStrengthUpdateRequest"); |
| 12350 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12351 | final int callingUid = Binder.getCallingUid(); |
| 12352 | // Verify that tha callingPackage belongs to the calling UID |
| 12353 | mApp.getSystemService(AppOpsManager.class) |
| 12354 | .checkPackage(callingUid, callingPackage); |
| 12355 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12356 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12357 | |
| 12358 | final long identity = Binder.clearCallingIdentity(); |
| 12359 | try { |
| 12360 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12361 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12362 | |
| 12363 | if (result instanceof IllegalStateException) { |
| 12364 | throw (IllegalStateException) result; |
| 12365 | } |
| 12366 | } finally { |
| 12367 | Binder.restoreCallingIdentity(identity); |
| 12368 | } |
| 12369 | } |
| 12370 | |
| 12371 | @Override |
| 12372 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 12373 | String callingPackage) { |
| 12374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 12375 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 12376 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12377 | enforceTelephonyFeatureWithException(callingPackage, |
| 12378 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, "clearSignalStrengthUpdateRequest"); |
| 12379 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12380 | final int callingUid = Binder.getCallingUid(); |
| 12381 | // Verify that tha callingPackage belongs to the calling UID |
| 12382 | mApp.getSystemService(AppOpsManager.class) |
| 12383 | .checkPackage(callingUid, callingPackage); |
| 12384 | |
| 12385 | final long identity = Binder.clearCallingIdentity(); |
| 12386 | try { |
| 12387 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 12388 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 12389 | |
| 12390 | if (result instanceof IllegalStateException) { |
| 12391 | throw (IllegalStateException) result; |
| 12392 | } |
| 12393 | } finally { |
| 12394 | Binder.restoreCallingIdentity(identity); |
| 12395 | } |
| 12396 | } |
| 12397 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12398 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 12399 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | b7a95a4 | 2024-03-07 04:57:29 +0000 | [diff] [blame] | 12400 | if (TelephonyPermissions.isSystemOrPhone(callingUid)) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12401 | // phone/system process do not have further restriction on request |
| 12402 | return; |
| 12403 | } |
| 12404 | |
| 12405 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12406 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12407 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 12408 | context.enforceCallingOrSelfPermission( |
| 12409 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 12410 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12411 | } |
| 12412 | |
| 12413 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 12414 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12415 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 12416 | || info.isEnabled()) { |
| 12417 | throw new IllegalArgumentException( |
| 12418 | "Only system can set hide fields in SignalThresholdInfo"); |
| 12419 | } |
| 12420 | |
| 12421 | // Thresholds length for each RAN need in range. This has been validated in |
| 12422 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 12423 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 12424 | final int[] thresholds = info.getThresholds(); |
| 12425 | Objects.requireNonNull(thresholds); |
| 12426 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 12427 | || thresholds.length |
| 12428 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 12429 | throw new IllegalArgumentException( |
| 12430 | "thresholds length is out of range: " + thresholds.length); |
| 12431 | } |
| 12432 | } |
| 12433 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12434 | |
| 12435 | /** |
| 12436 | * Gets the current phone capability. |
| 12437 | * |
| 12438 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 12439 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 12440 | * It's used to evaluate possible phone config change, for example from single |
| 12441 | * SIM device to multi-SIM device. |
| 12442 | */ |
| 12443 | @Override |
| 12444 | public PhoneCapability getPhoneCapability() { |
| 12445 | enforceReadPrivilegedPermission("getPhoneCapability"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12446 | |
| 12447 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12448 | PackageManager.FEATURE_TELEPHONY, "getPhoneCapability"); |
| 12449 | |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 12450 | final long identity = Binder.clearCallingIdentity(); |
| 12451 | try { |
| 12452 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 12453 | } finally { |
| 12454 | Binder.restoreCallingIdentity(identity); |
| 12455 | } |
| 12456 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12457 | |
| 12458 | /** |
| 12459 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 12460 | * required to be done shortly after the API is invoked. |
| 12461 | */ |
| 12462 | @Override |
| 12463 | @TelephonyManager.PrepareUnattendedRebootResult |
| 12464 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12465 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12466 | enforceRebootPermission(); |
| 12467 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12468 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12469 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "prepareForUnattendedReboot"); |
| 12470 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12471 | final long identity = Binder.clearCallingIdentity(); |
| 12472 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 12473 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 12474 | } finally { |
| 12475 | Binder.restoreCallingIdentity(identity); |
| 12476 | } |
| 12477 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12478 | |
| 12479 | /** |
| 12480 | * Request to get the current slicing configuration including URSP rules and |
| 12481 | * NSSAIs (configured, allowed and rejected). |
| 12482 | * |
| 12483 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 12484 | */ |
| 12485 | @Override |
| 12486 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 12487 | TelephonyPermissions |
| 12488 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 12489 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12490 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12491 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12492 | PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS, |
| 12493 | "getSlicingConfig"); |
| 12494 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 12495 | final long identity = Binder.clearCallingIdentity(); |
| 12496 | try { |
| 12497 | Phone phone = getDefaultPhone(); |
| 12498 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 12499 | } finally { |
| 12500 | Binder.restoreCallingIdentity(identity); |
| 12501 | } |
| 12502 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12503 | |
| 12504 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12505 | * Check whether the given premium capability is available for purchase from the carrier. |
| 12506 | * |
| 12507 | * @param capability The premium capability to check. |
| 12508 | * @param subId The subId to check the premium capability for. |
| 12509 | * |
| 12510 | * @return Whether the given premium capability is available to purchase. |
| 12511 | */ |
| 12512 | @Override |
| 12513 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 12514 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12515 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 12516 | log("Premium capability " |
| 12517 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12518 | + " is not available for purchase due to missing permissions."); |
| 12519 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 12520 | + "permission READ_BASIC_PHONE_STATE."); |
| 12521 | } |
| 12522 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12523 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12524 | PackageManager.FEATURE_TELEPHONY_DATA, "isPremiumCapabilityAvailableForPurchase"); |
| 12525 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12526 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 12527 | if (phone == null) { |
| 12528 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 12529 | return false; |
| 12530 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12531 | final long identity = Binder.clearCallingIdentity(); |
| 12532 | try { |
Sarah Chin | cc5446f | 2023-10-23 17:57:19 -0700 | [diff] [blame] | 12533 | return SlicePurchaseController.getInstance(phone, mFeatureFlags) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12534 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 12535 | } finally { |
| 12536 | Binder.restoreCallingIdentity(identity); |
| 12537 | } |
| 12538 | } |
| 12539 | |
| 12540 | /** |
| 12541 | * Purchase the given premium capability from the carrier. |
| 12542 | * |
| 12543 | * @param capability The premium capability to purchase. |
| 12544 | * @param callback The result of the purchase request. |
| 12545 | * @param subId The subId to purchase the premium capability for. |
| 12546 | */ |
| 12547 | @Override |
| 12548 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 12549 | log("purchasePremiumCapability: capability=" |
| 12550 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 12551 | + getCurrentPackageName()); |
| 12552 | |
| 12553 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 12554 | mApp, "purchasePremiumCapability")) { |
| 12555 | log("purchasePremiumCapability " |
| 12556 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12557 | + " failed due to missing permissions."); |
| 12558 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 12559 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12560 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 12561 | mApp, "purchasePremiumCapability")) { |
| 12562 | log("purchasePremiumCapability " |
| 12563 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12564 | + " failed due to missing permissions."); |
| 12565 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12566 | } |
| 12567 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12568 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12569 | PackageManager.FEATURE_TELEPHONY_DATA, "purchasePremiumCapability"); |
| 12570 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12571 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 12572 | if (phone == null) { |
| 12573 | try { |
| 12574 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 12575 | callback.accept(result); |
| 12576 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 12577 | } catch (RemoteException e) { |
| 12578 | String logStr = "Purchase premium capability " |
| 12579 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12580 | + " failed due to RemoteException handling null phone: " + e; |
| 12581 | if (DBG) log(logStr); |
| 12582 | AnomalyReporter.reportAnomaly( |
| 12583 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12584 | } |
| 12585 | return; |
| 12586 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12587 | |
| 12588 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12589 | try { |
Jack Yu | be3fa44 | 2024-09-16 14:39:45 -0700 | [diff] [blame] | 12590 | if (mFeatureFlags.hsumPackageManager()) { |
| 12591 | callingProcess = mApp.getPackageManager().getApplicationInfoAsUser( |
| 12592 | getCurrentPackageName(), 0, Binder.getCallingUserHandle()).processName; |
| 12593 | } else { |
| 12594 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 12595 | getCurrentPackageName(), 0).processName; |
| 12596 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12597 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12598 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12599 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12600 | |
| 12601 | boolean isVisible = false; |
| 12602 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 12603 | if (am != null) { |
| 12604 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 12605 | if (processes != null) { |
| 12606 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 12607 | log("purchasePremiumCapability: process " + process.processName |
Sarah Chin | ff8b180 | 2023-04-11 14:22:14 -0700 | [diff] [blame] | 12608 | + " has importance " + process.importance); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 12609 | if (process.processName.equals(callingProcess) && process.importance |
| 12610 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 12611 | isVisible = true; |
| 12612 | break; |
| 12613 | } |
| 12614 | } |
| 12615 | } |
| 12616 | } |
| 12617 | |
| 12618 | if (!isVisible) { |
| 12619 | try { |
| 12620 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 12621 | callback.accept(result); |
| 12622 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 12623 | } catch (RemoteException e) { |
| 12624 | String logStr = "Purchase premium capability " |
| 12625 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 12626 | + " failed due to RemoteException handling background application: " + e; |
| 12627 | if (DBG) log(logStr); |
| 12628 | AnomalyReporter.reportAnomaly( |
| 12629 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 12630 | } |
| 12631 | return; |
| 12632 | } |
| 12633 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 12634 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 12635 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 12636 | } |
| 12637 | |
| 12638 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12639 | * Register an IMS connection state callback |
| 12640 | */ |
| 12641 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12642 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 12643 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12644 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 12645 | // ImsMmTelManager |
| 12646 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 12647 | TelephonyPermissions |
| 12648 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 12649 | mApp, subId, "registerImsStateCallback"); |
| 12650 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 12651 | // ImsRcsManager or SipDelegateManager |
| 12652 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 12653 | Binder.getCallingUid(), "registerImsStateCallback", |
| 12654 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12655 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 12656 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 12657 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 12658 | } |
| 12659 | |
| 12660 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 12661 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12662 | "IMS not available on device."); |
| 12663 | } |
| 12664 | |
| 12665 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 12666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 12667 | } |
| 12668 | |
| 12669 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12670 | if (controller == null) { |
| 12671 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 12672 | "IMS not available on device."); |
| 12673 | } |
| 12674 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12675 | if (callingPackage == null) { |
| 12676 | callingPackage = getCurrentPackageName(); |
| 12677 | } |
| 12678 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12679 | final long token = Binder.clearCallingIdentity(); |
| 12680 | try { |
| 12681 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 12682 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 12683 | } catch (ImsException e) { |
| 12684 | throw new ServiceSpecificException(e.getCode()); |
| 12685 | } finally { |
| 12686 | Binder.restoreCallingIdentity(token); |
| 12687 | } |
| 12688 | } |
| 12689 | |
| 12690 | /** |
| 12691 | * Unregister an IMS connection state callback |
| 12692 | */ |
| 12693 | @Override |
| 12694 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 12695 | final long token = Binder.clearCallingIdentity(); |
| 12696 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 12697 | if (controller == null) { |
| 12698 | return; |
| 12699 | } |
| 12700 | try { |
| 12701 | controller.unregisterImsStateCallback(cb); |
| 12702 | } finally { |
| 12703 | Binder.restoreCallingIdentity(token); |
| 12704 | } |
| 12705 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12706 | |
| 12707 | /** |
| 12708 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 12709 | * |
| 12710 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12711 | * {@link android.Manifest.permission#ACCESS_LAST_KNOWN_CELL_ID}, otherwise throws |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12712 | * SecurityException. |
Pranav Madapurmath | 3ec7117 | 2023-12-05 23:46:25 +0000 | [diff] [blame] | 12713 | * |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12714 | * If there is current registered network this value will be same as the registered cell |
| 12715 | * identity. If the device goes out of service the previous cell identity is cached and |
| 12716 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 12717 | * it will be cleared and null will be returned. |
| 12718 | * |
| 12719 | */ |
| 12720 | @Override |
| 12721 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 12722 | String callingFeatureId) { |
| 12723 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12724 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 12725 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 12726 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 12727 | .setCallingPackage(callingPackage) |
| 12728 | .setCallingFeatureId(callingFeatureId) |
| 12729 | .setCallingPid(Binder.getCallingPid()) |
| 12730 | .setCallingUid(Binder.getCallingUid()) |
| 12731 | .setMethod("getLastKnownCellIdentity") |
| 12732 | .setLogAsInfo(true) |
| 12733 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 12734 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 12735 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 12736 | .build()); |
| 12737 | |
| 12738 | boolean hasFinePermission = |
| 12739 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 12740 | if (!hasFinePermission |
| 12741 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 12742 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 12743 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12744 | } |
| 12745 | |
| 12746 | final long identity = Binder.clearCallingIdentity(); |
| 12747 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 12748 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 12749 | if (sst == null) return null; |
| 12750 | return sst.getLastKnownCellIdentity(); |
| 12751 | } finally { |
| 12752 | Binder.restoreCallingIdentity(identity); |
| 12753 | } |
| 12754 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 12755 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12756 | /** |
| 12757 | * Sets the modem service class Name that Telephony will bind to. |
| 12758 | * |
| 12759 | * @param serviceName The class name of the modem service. |
| 12760 | * @return true if the operation is succeed, otherwise false. |
| 12761 | */ |
| 12762 | public boolean setModemService(String serviceName) { |
| 12763 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 12764 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 12765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12766 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12767 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12768 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 12769 | } |
| 12770 | |
| 12771 | /** |
| 12772 | * Return the class name of the currently bounded modem service. |
| 12773 | * |
| 12774 | * @return the class name of the modem service. |
| 12775 | */ |
| 12776 | public String getModemService() { |
| 12777 | String result; |
| 12778 | Log.d(LOG_TAG, "getModemService"); |
| 12779 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 12780 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12781 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 12782 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 12783 | "getModemService"); |
| 12784 | result = mPhoneConfigurationManager.getModemService(); |
| 12785 | Log.d(LOG_TAG, "result = " + result); |
| 12786 | return result; |
| 12787 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12788 | |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12789 | /** |
| 12790 | * Get the aggregated satellite plmn list. This API collects plmn data from multiple sources, |
| 12791 | * including carrier config, entitlement server, and config update. |
| 12792 | * |
| 12793 | * @param subId subId The subscription ID of the carrier. |
| 12794 | * |
| 12795 | * @return List of plmns for carrier satellite service. If no plmn is available, empty list will |
| 12796 | * be returned. |
| 12797 | * |
| 12798 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12799 | */ |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12800 | @NonNull public List<String> getSatellitePlmnsForCarrier(int subId) { |
| 12801 | enforceSatelliteCommunicationPermission("getSatellitePlmnsForCarrier"); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12802 | final long identity = Binder.clearCallingIdentity(); |
| 12803 | try { |
Hakjun Choi | 74c16be | 2024-01-19 08:18:09 +0000 | [diff] [blame] | 12804 | return mSatelliteController.getSatellitePlmnsForCarrier(subId); |
Hakjun Choi | 3ee8111 | 2023-12-19 15:40:58 +0000 | [diff] [blame] | 12805 | } finally { |
| 12806 | Binder.restoreCallingIdentity(identity); |
| 12807 | } |
| 12808 | } |
| 12809 | |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12810 | @Override |
| 12811 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 12812 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 12813 | mApp.enforceCallingOrSelfPermission( |
| 12814 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 12815 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12816 | |
| 12817 | final long identity = Binder.clearCallingIdentity(); |
| 12818 | try { |
| 12819 | Phone phone = getPhone(subId); |
| 12820 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 12821 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 12822 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 12823 | phone.setVoiceServiceStateOverride(hasService); |
| 12824 | } finally { |
| 12825 | Binder.restoreCallingIdentity(identity); |
| 12826 | } |
| 12827 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12828 | |
| 12829 | /** |
| 12830 | * set removable eSIM as default eUICC. |
| 12831 | * |
| 12832 | * @hide |
| 12833 | */ |
| 12834 | @Override |
| 12835 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 12836 | enforceModifyPermission(); |
| 12837 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12838 | |
| 12839 | final long identity = Binder.clearCallingIdentity(); |
| 12840 | try { |
| 12841 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 12842 | } finally { |
| 12843 | Binder.restoreCallingIdentity(identity); |
| 12844 | } |
| 12845 | } |
| 12846 | |
| 12847 | /** |
| 12848 | * Returns whether the removable eSIM is default eUICC or not. |
| 12849 | * |
| 12850 | * @hide |
| 12851 | */ |
| 12852 | @Override |
| 12853 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 12854 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 12855 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 12856 | |
| 12857 | final long identity = Binder.clearCallingIdentity(); |
| 12858 | try { |
| 12859 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 12860 | } finally { |
| 12861 | Binder.restoreCallingIdentity(identity); |
| 12862 | } |
| 12863 | } |
| 12864 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12865 | /** |
| 12866 | * Get the component name of the default app to direct respond-via-message intent for the |
| 12867 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 12868 | * application currently configured for this user. |
| 12869 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 12870 | * {@code null} if the functionality is not supported. |
| 12871 | * @hide |
| 12872 | */ |
| 12873 | @Override |
| 12874 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 12875 | boolean updateIfNeeded) { |
| 12876 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 12877 | |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 12878 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 12879 | PackageManager.FEATURE_TELEPHONY_MESSAGING, |
| 12880 | "getDefaultRespondViaMessageApplication"); |
| 12881 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 12882 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 12883 | |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12884 | if (mTelecomFeatureFlags.telecomMainUserInGetRespondMessageApp()){ |
| 12885 | UserHandle mainUser = null; |
| 12886 | Context userContext = null; |
| 12887 | final long identity = Binder.clearCallingIdentity(); |
| 12888 | try { |
| 12889 | mainUser = mUserManager.getMainUser(); |
| 12890 | userContext = context.createContextAsUser(mainUser, 0); |
| 12891 | Log.d(LOG_TAG, "getDefaultRespondViaMessageApplication: mainUser = " + mainUser); |
| 12892 | } finally { |
| 12893 | Binder.restoreCallingIdentity(identity); |
| 12894 | } |
| 12895 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(userContext, |
| 12896 | updateIfNeeded, mainUser); |
| 12897 | } else { |
| 12898 | UserHandle userHandle = null; |
| 12899 | final long identity = Binder.clearCallingIdentity(); |
| 12900 | try { |
| 12901 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 12902 | } finally { |
| 12903 | Binder.restoreCallingIdentity(identity); |
| 12904 | } |
| 12905 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 12906 | updateIfNeeded, userHandle); |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12907 | } |
Grant Menke | b037249 | 2024-09-19 18:01:29 -0700 | [diff] [blame] | 12908 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 12909 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12910 | |
| 12911 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12912 | * Set whether the device is able to connect with null ciphering or integrity |
| 12913 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 12914 | * and all new subscriptions after this. |
| 12915 | * |
| 12916 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 12917 | * @hide |
| 12918 | */ |
| 12919 | @Override |
| 12920 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 12921 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 12922 | enforceModifyPermission(); |
| 12923 | checkForNullCipherAndIntegritySupport(); |
| 12924 | |
| 12925 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 12926 | // for listening to these preference changes and applying them immediately. |
| 12927 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 12928 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 12929 | editor.apply(); |
| 12930 | |
| 12931 | for (Phone phone: PhoneFactory.getPhones()) { |
| 12932 | phone.handleNullCipherEnabledChange(); |
| 12933 | } |
| 12934 | } |
| 12935 | |
| 12936 | |
| 12937 | /** |
| 12938 | * Get whether the device is able to connect with null ciphering or integrity |
| 12939 | * algorithms. Note that this retrieves the phone-global preference and not |
| 12940 | * the state of the radio. |
| 12941 | * |
| 12942 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 12943 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 12944 | * version for this feature. |
| 12945 | * @hide |
| 12946 | */ |
| 12947 | @Override |
| 12948 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 12949 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 12950 | enforceReadPermission(); |
| 12951 | checkForNullCipherAndIntegritySupport(); |
| 12952 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 12953 | } |
| 12954 | |
| 12955 | private void checkForNullCipherAndIntegritySupport() { |
| 12956 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 12957 | throw new UnsupportedOperationException( |
| 12958 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 12959 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 12960 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 12961 | throw new UnsupportedOperationException( |
| 12962 | "Null cipher and integrity operations unsupported by modem"); |
| 12963 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12964 | } |
| 12965 | |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 12966 | private void checkForIdentifierDisclosureNotificationSupport() { |
| 12967 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_IDENTIFIER_DISCLOSURE_VERSION) { |
| 12968 | throw new UnsupportedOperationException( |
| 12969 | "Cellular identifier disclosure transparency operations require HAL 2.2 or " |
| 12970 | + "above"); |
| 12971 | } |
| 12972 | if (!getDefaultPhone().isIdentifierDisclosureTransparencySupported()) { |
| 12973 | throw new UnsupportedOperationException( |
| 12974 | "Cellular identifier disclosure transparency operations unsupported by modem"); |
| 12975 | } |
| 12976 | } |
| 12977 | |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 12978 | private void checkForNullCipherNotificationSupport() { |
| 12979 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_NOTIFICATION_VERSION) { |
| 12980 | throw new UnsupportedOperationException( |
| 12981 | "Null cipher notification operations require HAL 2.2 or above"); |
| 12982 | } |
| 12983 | if (!getDefaultPhone().isNullCipherNotificationSupported()) { |
| 12984 | throw new UnsupportedOperationException( |
| 12985 | "Null cipher notification operations unsupported by modem"); |
| 12986 | } |
| 12987 | } |
| 12988 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 12989 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12990 | * Get the SIM state for the slot index. |
| 12991 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12992 | * |
| 12993 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12994 | */ |
| 12995 | @Override |
| 12996 | @SimState |
| 12997 | public int getSimStateForSlotIndex(int slotIndex) { |
Tomasz Wasilczyk | 751bb1b | 2024-06-04 12:03:46 -0700 | [diff] [blame] | 12998 | if (!mApp.getResources().getBoolean( |
| 12999 | com.android.internal.R.bool.config_force_phone_globals_creation)) { |
| 13000 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13001 | PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION, "getSimStateForSlotIndex"); |
| 13002 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13003 | |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 13004 | IccCardConstants.State simState; |
| 13005 | if (slotIndex < 0) { |
| 13006 | simState = IccCardConstants.State.UNKNOWN; |
| 13007 | } else { |
| 13008 | Phone phone = null; |
| 13009 | try { |
| 13010 | phone = PhoneFactory.getPhone(slotIndex); |
| 13011 | } catch (IllegalStateException e) { |
| 13012 | // ignore |
| 13013 | } |
| 13014 | if (phone == null) { |
| 13015 | simState = IccCardConstants.State.UNKNOWN; |
| 13016 | } else { |
| 13017 | IccCard icc = phone.getIccCard(); |
| 13018 | if (icc == null) { |
| 13019 | simState = IccCardConstants.State.UNKNOWN; |
| 13020 | } else { |
| 13021 | simState = icc.getState(); |
| 13022 | } |
| 13023 | } |
| 13024 | } |
| 13025 | return simState.ordinal(); |
| 13026 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13027 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13028 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 13029 | boolean enableLogcat, |
| 13030 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13031 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13032 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13033 | TelephonyManager.EmergencyCallDiagnosticData.Builder ecdDataBuilder = |
| 13034 | new TelephonyManager.EmergencyCallDiagnosticData.Builder(); |
| 13035 | ecdDataBuilder |
| 13036 | .setTelecomDumpsysCollectionEnabled(enableTelecomDump) |
| 13037 | .setTelephonyDumpsysCollectionEnabled(enableTelephonyDump); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13038 | if (enableLogcat) { |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13039 | ecdDataBuilder.setLogcatCollectionStartTimeMillis(logcatStartTimestampMillis); |
Pranav Madapurmath | ef6eeec | 2023-12-14 16:42:42 -0800 | [diff] [blame] | 13040 | } |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13041 | TelephonyManager.EmergencyCallDiagnosticData ecdData = ecdDataBuilder.build(); |
| 13042 | Log.d(LOG_TAG, "persisting with Params " + ecdData.toString()); |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 13043 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 13044 | Executors.newCachedThreadPool(), db, |
| 13045 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13046 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), ecdData, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13047 | } |
| 13048 | |
| 13049 | /** |
| 13050 | * Request telephony to persist state for debugging emergency call failures. |
| 13051 | * |
Pranav Madapurmath | 8883dbc | 2024-02-01 10:22:25 -0800 | [diff] [blame] | 13052 | * @param dropboxTag Tag to use when persisting data to dropbox service. |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13053 | * @param enableLogcat whether to collect logcat output |
| 13054 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 13055 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 13056 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 13057 | */ |
| 13058 | @Override |
| 13059 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 13060 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 13061 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 13062 | boolean enableTelephonyDump) { |
Pranav Madapurmath | 1767aaf | 2024-03-05 13:13:52 -0800 | [diff] [blame] | 13063 | // Verify that the caller has READ_DROPBOX_DATA permission. |
| 13064 | if (mTelecomFeatureFlags.telecomResolveHiddenDependencies() |
| 13065 | && Flags.enableReadDropboxPermission()) { |
| 13066 | mApp.enforceCallingPermission(permission.READ_DROPBOX_DATA, |
| 13067 | "persistEmergencyCallDiagnosticData"); |
| 13068 | } else { |
| 13069 | // Otherwise, enforce legacy permission. |
| 13070 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 13071 | "persistEmergencyCallDiagnosticData"); |
| 13072 | } |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 13073 | final long identity = Binder.clearCallingIdentity(); |
| 13074 | try { |
| 13075 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 13076 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 13077 | |
| 13078 | } finally { |
| 13079 | Binder.restoreCallingIdentity(identity); |
| 13080 | } |
| 13081 | } |
| 13082 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13083 | /** |
| 13084 | * Get current cell broadcast ranges. |
| 13085 | */ |
| 13086 | @Override |
| 13087 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13088 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 13089 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13090 | "getCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13091 | |
| 13092 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13093 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "getCellBroadcastIdRanges"); |
| 13094 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13095 | final long identity = Binder.clearCallingIdentity(); |
| 13096 | try { |
| 13097 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 13098 | } finally { |
| 13099 | Binder.restoreCallingIdentity(identity); |
| 13100 | } |
| 13101 | } |
| 13102 | |
| 13103 | /** |
| 13104 | * Set reception of cell broadcast messages with the list of the given ranges |
| 13105 | * |
| 13106 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 13107 | */ |
| 13108 | @Override |
| 13109 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 13110 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 13111 | @Nullable IIntegerConsumer callback) { |
| 13112 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 13113 | "setCellBroadcastIdRanges"); |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 13114 | |
| 13115 | enforceTelephonyFeatureWithException(getCurrentPackageName(), |
| 13116 | PackageManager.FEATURE_TELEPHONY_MESSAGING, "setCellBroadcastIdRanges"); |
| 13117 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 13118 | final long identity = Binder.clearCallingIdentity(); |
| 13119 | try { |
| 13120 | Phone phone = getPhoneFromSubId(subId); |
| 13121 | if (DBG) { |
| 13122 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 13123 | } |
| 13124 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 13125 | if (callback != null) { |
| 13126 | try { |
| 13127 | callback.accept(result); |
| 13128 | } catch (RemoteException e) { |
| 13129 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 13130 | } |
| 13131 | } |
| 13132 | }); |
| 13133 | } finally { |
| 13134 | Binder.restoreCallingIdentity(identity); |
| 13135 | } |
| 13136 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 13137 | |
| 13138 | /** |
| 13139 | * Returns whether the device supports the domain selection service. |
| 13140 | * |
| 13141 | * @return {@code true} if the device supports the domain selection service. |
| 13142 | */ |
| 13143 | @Override |
| 13144 | public boolean isDomainSelectionSupported() { |
| 13145 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13146 | "isDomainSelectionSupported"); |
| 13147 | |
| 13148 | final long identity = Binder.clearCallingIdentity(); |
| 13149 | try { |
| 13150 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 13151 | } finally { |
| 13152 | Binder.restoreCallingIdentity(identity); |
| 13153 | } |
| 13154 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 13155 | |
| 13156 | /** |
Hunsuk Choi | 9c69a80 | 2024-04-11 20:39:23 +0000 | [diff] [blame] | 13157 | * Returns whether the AOSP domain selection service is supported. |
| 13158 | * |
| 13159 | * @return {@code true} if the AOSP domain selection service is supported, |
| 13160 | * {@code false} otherwise. |
| 13161 | */ |
| 13162 | @Override |
| 13163 | public boolean isAospDomainSelectionService() { |
| 13164 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 13165 | "isAospDomainSelectionService"); |
| 13166 | |
| 13167 | final long identity = Binder.clearCallingIdentity(); |
| 13168 | try { |
| 13169 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 13170 | String dssComponentName = mApp.getResources().getString( |
| 13171 | R.string.config_domain_selection_service_component_name); |
| 13172 | ComponentName componentName = ComponentName.createRelative(mApp.getPackageName(), |
| 13173 | TelephonyDomainSelectionService.class.getName()); |
| 13174 | Log.i(LOG_TAG, "isAospDomainSelectionService dss=" + dssComponentName |
| 13175 | + ", aosp=" + componentName.flattenToString()); |
| 13176 | return TextUtils.equals(componentName.flattenToString(), dssComponentName); |
| 13177 | } |
| 13178 | } finally { |
| 13179 | Binder.restoreCallingIdentity(identity); |
| 13180 | } |
| 13181 | return false; |
| 13182 | } |
| 13183 | |
| 13184 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13185 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 13186 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 13187 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13188 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13189 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 13190 | * {@code false} to disable. |
| 13191 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13192 | * @param isEmergency {@code true} to enable emergency mode, {@code false} otherwise. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13193 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13194 | * |
| 13195 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13196 | */ |
| 13197 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13198 | public void requestSatelliteEnabled(boolean enableSatellite, boolean enableDemoMode, |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13199 | boolean isEmergency, @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13200 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13201 | final long identity = Binder.clearCallingIdentity(); |
| 13202 | try { |
| 13203 | if (enableSatellite) { |
| 13204 | ResultReceiver resultReceiver = new ResultReceiver(mMainThreadHandler) { |
| 13205 | @Override |
| 13206 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 13207 | Log.d(LOG_TAG, "Satellite access restriction resultCode=" + resultCode |
| 13208 | + ", resultData=" + resultData); |
| 13209 | boolean isAllowed = false; |
| 13210 | Consumer<Integer> result = FunctionalUtils.ignoreRemoteException( |
| 13211 | callback::accept); |
| 13212 | if (resultCode == SATELLITE_RESULT_SUCCESS) { |
| 13213 | if (resultData != null |
| 13214 | && resultData.containsKey( |
| 13215 | KEY_SATELLITE_COMMUNICATION_ALLOWED)) { |
| 13216 | isAllowed = resultData.getBoolean( |
| 13217 | KEY_SATELLITE_COMMUNICATION_ALLOWED); |
| 13218 | } else { |
| 13219 | loge("KEY_SATELLITE_COMMUNICATION_ALLOWED does not exist."); |
| 13220 | } |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13221 | } else { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13222 | result.accept(resultCode); |
| 13223 | return; |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13224 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13225 | if (isAllowed) { |
| 13226 | mSatelliteController.requestSatelliteEnabled( |
| 13227 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13228 | } else { |
| 13229 | result.accept(SATELLITE_RESULT_ACCESS_BARRED); |
| 13230 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 13231 | } |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13232 | }; |
| 13233 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation( |
| 13234 | resultReceiver, true); |
| 13235 | } else { |
| 13236 | // No need to check if satellite is allowed at current location when disabling |
| 13237 | // satellite |
| 13238 | mSatelliteController.requestSatelliteEnabled( |
| 13239 | enableSatellite, enableDemoMode, isEmergency, callback); |
| 13240 | } |
| 13241 | } finally { |
| 13242 | Binder.restoreCallingIdentity(identity); |
Thomas Nguyen | 060f5e0 | 2024-01-24 16:44:50 -0800 | [diff] [blame] | 13243 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13244 | } |
| 13245 | |
| 13246 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13247 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13248 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13249 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 13250 | * if the request is successful or an error code if the request failed. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13251 | * |
| 13252 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13253 | */ |
| 13254 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13255 | public void requestIsSatelliteEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13256 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13257 | final long identity = Binder.clearCallingIdentity(); |
| 13258 | try { |
| 13259 | mSatelliteController.requestIsSatelliteEnabled(result); |
| 13260 | } finally { |
| 13261 | Binder.restoreCallingIdentity(identity); |
| 13262 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13263 | } |
| 13264 | |
| 13265 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13266 | * Request to get whether the satellite service demo mode is enabled. |
| 13267 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13268 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 13269 | * if the request is successful or an error code if the request failed. |
| 13270 | * |
| 13271 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13272 | */ |
| 13273 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13274 | public void requestIsDemoModeEnabled(@NonNull ResultReceiver result) { |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13275 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13276 | final long identity = Binder.clearCallingIdentity(); |
| 13277 | try { |
| 13278 | mSatelliteController.requestIsDemoModeEnabled(result); |
| 13279 | } finally { |
| 13280 | Binder.restoreCallingIdentity(identity); |
| 13281 | } |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13282 | } |
| 13283 | |
| 13284 | /** |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13285 | * Request to get whether the satellite service is enabled with emergency mode. |
| 13286 | * |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13287 | * @param result The result receiver that returns whether the satellite emergency mode is |
| 13288 | * enabled if the request is successful or an error code if the request failed. |
| 13289 | * |
| 13290 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13291 | */ |
| 13292 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13293 | public void requestIsEmergencyModeEnabled(@NonNull ResultReceiver result) { |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13294 | enforceSatelliteCommunicationPermission("requestIsEmergencyModeEnabled"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13295 | final long identity = Binder.clearCallingIdentity(); |
| 13296 | try { |
| 13297 | mSatelliteController.requestIsEmergencyModeEnabled(result); |
| 13298 | } finally { |
| 13299 | Binder.restoreCallingIdentity(identity); |
| 13300 | } |
Thomas Nguyen | a806267 | 2024-02-05 14:18:19 -0800 | [diff] [blame] | 13301 | } |
| 13302 | |
| 13303 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13304 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13305 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13306 | * @param result The result receiver that returns whether the satellite service is supported on |
| 13307 | * the device if the request is successful or an error code if the request failed. |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13308 | * |
| 13309 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13310 | */ |
| 13311 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13312 | public void requestIsSatelliteSupported(@NonNull ResultReceiver result) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13313 | enforceSatelliteCommunicationPermission("requestIsSatelliteSupported"); |
| 13314 | final long identity = Binder.clearCallingIdentity(); |
| 13315 | try { |
| 13316 | mSatelliteController.requestIsSatelliteSupported(result); |
| 13317 | } finally { |
| 13318 | Binder.restoreCallingIdentity(identity); |
| 13319 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13320 | } |
| 13321 | |
| 13322 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13323 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13324 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13325 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 13326 | * if the request is successful or an error code if the request failed. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13327 | * |
| 13328 | * @throws SecurityException if the caller doesn't have required permission. |
| 13329 | */ |
| 13330 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13331 | public void requestSatelliteCapabilities(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13332 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13333 | final long identity = Binder.clearCallingIdentity(); |
| 13334 | try { |
| 13335 | mSatelliteController.requestSatelliteCapabilities(result); |
| 13336 | } finally { |
| 13337 | Binder.restoreCallingIdentity(identity); |
| 13338 | } |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13339 | } |
| 13340 | |
| 13341 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13342 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13343 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 13344 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 13345 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13346 | * @param resultCallback The callback to get the result of the request. |
| 13347 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13348 | * |
| 13349 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13350 | */ |
| 13351 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13352 | public void startSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13353 | @NonNull IIntegerConsumer resultCallback, |
| 13354 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13355 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13356 | final long identity = Binder.clearCallingIdentity(); |
| 13357 | try { |
| 13358 | mSatelliteController.startSatelliteTransmissionUpdates(resultCallback, callback); |
| 13359 | } finally { |
| 13360 | Binder.restoreCallingIdentity(identity); |
| 13361 | } |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13362 | } |
| 13363 | |
| 13364 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13365 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13366 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 13367 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13368 | * @param resultCallback The callback to get the result of the request. |
| 13369 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13370 | * IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 13371 | * |
| 13372 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 13373 | */ |
| 13374 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13375 | public void stopSatelliteTransmissionUpdates( |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13376 | @NonNull IIntegerConsumer resultCallback, |
| 13377 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 13378 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13379 | final long identity = Binder.clearCallingIdentity(); |
| 13380 | try { |
| 13381 | mSatelliteController.stopSatelliteTransmissionUpdates(resultCallback, callback); |
| 13382 | } finally { |
| 13383 | Binder.restoreCallingIdentity(identity); |
| 13384 | } |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 13385 | } |
| 13386 | |
| 13387 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13388 | * Register the subscription with a satellite provider. |
| 13389 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 13390 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13391 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 13392 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13393 | * @param provisionData Data from the provisioning app that can be used by provisioning server |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13394 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13395 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13396 | * @return The signal transport used by the caller to cancel the provision request, |
| 13397 | * or {@code null} if the request failed. |
| 13398 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13399 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13400 | */ |
| 13401 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13402 | @Nullable public ICancellationSignal provisionSatelliteService( |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13403 | @NonNull String token, @NonNull byte[] provisionData, |
| 13404 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13405 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13406 | final long identity = Binder.clearCallingIdentity(); |
| 13407 | try { |
| 13408 | return mSatelliteController.provisionSatelliteService(token, provisionData, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame] | 13409 | callback); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13410 | } finally { |
| 13411 | Binder.restoreCallingIdentity(identity); |
| 13412 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13413 | } |
| 13414 | |
| 13415 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13416 | * Unregister the device/subscription with the satellite provider. |
| 13417 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13418 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13419 | * should report as deprovisioned. |
| 13420 | * |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13421 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 13422 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13423 | * |
| 13424 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13425 | */ |
| 13426 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13427 | public void deprovisionSatelliteService( |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13428 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 13429 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Thomas Nguyen | 9c3d57b | 2024-10-23 20:17:21 +0000 | [diff] [blame] | 13430 | final long identity = Binder.clearCallingIdentity(); |
| 13431 | try { |
| 13432 | mSatelliteController.deprovisionSatelliteService(token, callback); |
| 13433 | } finally { |
| 13434 | Binder.restoreCallingIdentity(identity); |
| 13435 | } |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 13436 | } |
| 13437 | |
| 13438 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13439 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13440 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13441 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13442 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13443 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13444 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13445 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13446 | */ |
| 13447 | @Override |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13448 | @SatelliteManager.SatelliteResult public int registerForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13449 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 13450 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13451 | final long identity = Binder.clearCallingIdentity(); |
| 13452 | try { |
| 13453 | return mSatelliteController.registerForSatelliteProvisionStateChanged(callback); |
| 13454 | } finally { |
| 13455 | Binder.restoreCallingIdentity(identity); |
| 13456 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13457 | } |
| 13458 | |
| 13459 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13460 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13461 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13462 | * |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13463 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13464 | * {@link #registerForSatelliteProvisionStateChanged(ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13465 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13466 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13467 | */ |
| 13468 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13469 | public void unregisterForSatelliteProvisionStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13470 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13471 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13472 | final long identity = Binder.clearCallingIdentity(); |
| 13473 | try { |
| 13474 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(callback); |
| 13475 | } finally { |
| 13476 | Binder.restoreCallingIdentity(identity); |
| 13477 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13478 | } |
| 13479 | |
| 13480 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13481 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13482 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13483 | * @param result The result receiver that returns whether the device is provisioned with a |
| 13484 | * satellite provider if the request is successful or an error code if the |
| 13485 | * request failed. |
| 13486 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13487 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13488 | */ |
| 13489 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13490 | public void requestIsSatelliteProvisioned(@NonNull ResultReceiver result) { |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 13491 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13492 | final long identity = Binder.clearCallingIdentity(); |
| 13493 | try { |
| 13494 | mSatelliteController.requestIsSatelliteProvisioned(result); |
| 13495 | } finally { |
| 13496 | Binder.restoreCallingIdentity(identity); |
| 13497 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13498 | } |
| 13499 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13500 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13501 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13502 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13503 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13504 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13505 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13506 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13507 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13508 | */ |
| 13509 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13510 | @SatelliteManager.SatelliteResult public int registerForSatelliteModemStateChanged( |
Hakjun Choi | d4a52a2 | 2023-12-13 09:48:24 +0000 | [diff] [blame] | 13511 | @NonNull ISatelliteModemStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13512 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13513 | final long identity = Binder.clearCallingIdentity(); |
| 13514 | try { |
| 13515 | return mSatelliteController.registerForSatelliteModemStateChanged(callback); |
| 13516 | } finally { |
| 13517 | Binder.restoreCallingIdentity(identity); |
| 13518 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13519 | } |
| 13520 | |
| 13521 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 13522 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13523 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13524 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13525 | * @param callback The callback that was passed to |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13526 | * {@link #registerForModemStateChanged(int, ISatelliteModemStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13527 | * |
| 13528 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13529 | */ |
| 13530 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13531 | public void unregisterForModemStateChanged(@NonNull ISatelliteModemStateCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13532 | enforceSatelliteCommunicationPermission("unregisterForModemStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13533 | final long identity = Binder.clearCallingIdentity(); |
| 13534 | try { |
| 13535 | mSatelliteController.unregisterForModemStateChanged(callback); |
| 13536 | } finally { |
| 13537 | Binder.restoreCallingIdentity(identity); |
| 13538 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13539 | } |
| 13540 | |
| 13541 | /** |
| 13542 | * Register to receive incoming datagrams over satellite. |
| 13543 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13544 | * @param callback The callback to handle incoming datagrams over satellite. |
| 13545 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13546 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13547 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13548 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13549 | */ |
| 13550 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13551 | @SatelliteManager.SatelliteResult public int registerForIncomingDatagram( |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13552 | @NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13553 | enforceSatelliteCommunicationPermission("registerForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13554 | final long identity = Binder.clearCallingIdentity(); |
| 13555 | try { |
| 13556 | return mSatelliteController.registerForIncomingDatagram(callback); |
| 13557 | } finally { |
| 13558 | Binder.restoreCallingIdentity(identity); |
| 13559 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13560 | } |
| 13561 | |
| 13562 | /** |
| 13563 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 13564 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13565 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13566 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13567 | * {@link #registerForIncomingDatagram(ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13568 | * |
| 13569 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13570 | */ |
| 13571 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13572 | public void unregisterForIncomingDatagram(@NonNull ISatelliteDatagramCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13573 | enforceSatelliteCommunicationPermission("unregisterForIncomingDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13574 | final long identity = Binder.clearCallingIdentity(); |
| 13575 | try { |
| 13576 | mSatelliteController.unregisterForIncomingDatagram(callback); |
| 13577 | } finally { |
| 13578 | Binder.restoreCallingIdentity(identity); |
| 13579 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13580 | } |
| 13581 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13582 | /** |
| 13583 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13584 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13585 | * This method requests modem to check if there are any pending datagrams to be received over |
| 13586 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 0a78dfb | 2023-03-28 20:29:26 +0000 | [diff] [blame] | 13587 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, Consumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13588 | * |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13589 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13590 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13591 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13592 | */ |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13593 | public void pollPendingDatagrams(IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13594 | enforceSatelliteCommunicationPermission("pollPendingDatagrams"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13595 | final long identity = Binder.clearCallingIdentity(); |
| 13596 | try { |
| 13597 | mSatelliteController.pollPendingDatagrams(callback); |
| 13598 | } finally { |
| 13599 | Binder.restoreCallingIdentity(identity); |
| 13600 | } |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 13601 | } |
| 13602 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13603 | /** |
| 13604 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13605 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 13606 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 13607 | * input to this method. Datagram received here will be passed down to modem without any |
| 13608 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13609 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13610 | * @param datagramType datagram type indicating whether the datagram is of type |
| 13611 | * SOS_SMS or LOCATION_SHARING. |
| 13612 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 13613 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 13614 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 13615 | * full screen mode. |
Aishwarya Mallamapti | 1fd18f3 | 2023-08-25 00:23:13 +0000 | [diff] [blame] | 13616 | * @param callback The callback to get {@link SatelliteManager.SatelliteResult} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 13617 | * |
| 13618 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13619 | */ |
| 13620 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13621 | public void sendDatagram(@SatelliteManager.DatagramType int datagramType, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 13622 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 13623 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13624 | enforceSatelliteCommunicationPermission("sendDatagram"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13625 | final long identity = Binder.clearCallingIdentity(); |
| 13626 | try { |
| 13627 | mSatelliteController.sendDatagram(datagramType, datagram, needFullScreenPointingUI, |
| 13628 | callback); |
| 13629 | } finally { |
| 13630 | Binder.restoreCallingIdentity(identity); |
| 13631 | } |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 13632 | } |
| 13633 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13634 | /** |
| 13635 | * Request to get whether satellite communication is allowed for the current location. |
| 13636 | * |
| 13637 | * @param subId The subId of the subscription to check whether satellite communication is |
| 13638 | * allowed for the current location for. |
| 13639 | * @param result The result receiver that returns whether satellite communication is allowed |
| 13640 | * for the current location if the request is successful or an error code |
| 13641 | * if the request failed. |
| 13642 | * |
| 13643 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13644 | */ |
| 13645 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13646 | public void requestIsCommunicationAllowedForCurrentLocation(int subId, |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13647 | @NonNull ResultReceiver result) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13648 | enforceSatelliteCommunicationPermission("requestIsCommunicationAllowedForCurrentLocation"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13649 | final long identity = Binder.clearCallingIdentity(); |
| 13650 | try { |
| 13651 | mSatelliteAccessController.requestIsCommunicationAllowedForCurrentLocation(result, |
| 13652 | false); |
| 13653 | } finally { |
| 13654 | Binder.restoreCallingIdentity(identity); |
| 13655 | } |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13656 | } |
| 13657 | |
| 13658 | /** |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13659 | * Request to get the time after which the satellite will be visible. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13660 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 13661 | * @param result The result receiver that returns the time after which the satellite will |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13662 | * be visible if the request is successful or an error code if the request failed. |
| 13663 | * |
| 13664 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13665 | */ |
| 13666 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13667 | public void requestTimeForNextSatelliteVisibility(@NonNull ResultReceiver result) { |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 13668 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13669 | final long identity = Binder.clearCallingIdentity(); |
| 13670 | try { |
| 13671 | mSatelliteController.requestTimeForNextSatelliteVisibility(result); |
| 13672 | } finally { |
| 13673 | Binder.restoreCallingIdentity(identity); |
| 13674 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13675 | } |
| 13676 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 13677 | /** |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13678 | * Inform whether the device is aligned with the satellite in both real and demo mode. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13679 | * |
joonhunshin | 5910415 | 2024-09-11 09:55:35 +0000 | [diff] [blame] | 13680 | * @param isAligned {@code true} Device is aligned with the satellite. |
| 13681 | * {@code false} Device fails to align with the satellite. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13682 | * |
| 13683 | * @throws SecurityException if the caller doesn't have required permission. |
| 13684 | */ |
| 13685 | @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION) |
| 13686 | |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13687 | public void setDeviceAlignedWithSatellite(@NonNull boolean isAligned) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13688 | enforceSatelliteCommunicationPermission("setDeviceAlignedWithSatellite"); |
| 13689 | final long identity = Binder.clearCallingIdentity(); |
| 13690 | try { |
| 13691 | mSatelliteController.setDeviceAlignedWithSatellite(isAligned); |
| 13692 | } finally { |
| 13693 | Binder.restoreCallingIdentity(identity); |
| 13694 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 13695 | } |
| 13696 | |
| 13697 | /** |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13698 | * Add a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13699 | * by modem. |
| 13700 | * |
| 13701 | * @param subId The subId of the subscription to request for. |
| 13702 | * @param reason Reason for disallowing satellite communication for carrier. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13703 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13704 | * operation. |
| 13705 | * |
| 13706 | * @throws SecurityException if the caller doesn't have required permission. |
| 13707 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13708 | public void addAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13709 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13710 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13711 | enforceSatelliteCommunicationPermission("addAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13712 | final long identity = Binder.clearCallingIdentity(); |
| 13713 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13714 | mSatelliteController.addAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13715 | } finally { |
| 13716 | Binder.restoreCallingIdentity(identity); |
| 13717 | } |
| 13718 | } |
| 13719 | |
| 13720 | /** |
| 13721 | * Remove a restriction reason for disallowing carrier supported satellite plmn scan and attach |
| 13722 | * by modem. |
| 13723 | * |
| 13724 | * @param subId The subId of the subscription to request for. |
| 13725 | * @param reason Reason for disallowing satellite communication. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13726 | * @param callback Listener for the {@link SatelliteManager.SatelliteResult} result of the |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13727 | * operation. |
| 13728 | * |
| 13729 | * @throws SecurityException if the caller doesn't have required permission. |
| 13730 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13731 | public void removeAttachRestrictionForCarrier(int subId, |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13732 | @SatelliteManager.SatelliteCommunicationRestrictionReason int reason, |
| 13733 | @NonNull IIntegerConsumer callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13734 | enforceSatelliteCommunicationPermission("removeAttachRestrictionForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13735 | final long identity = Binder.clearCallingIdentity(); |
| 13736 | try { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13737 | mSatelliteController.removeAttachRestrictionForCarrier(subId, reason, callback); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13738 | } finally { |
| 13739 | Binder.restoreCallingIdentity(identity); |
| 13740 | } |
| 13741 | } |
| 13742 | |
| 13743 | /** |
| 13744 | * Get reasons for disallowing satellite communication, as requested by |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13745 | * {@link #addAttachRestrictionForCarrier(int, int, IIntegerConsumer)}. |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13746 | * |
| 13747 | * @param subId The subId of the subscription to request for. |
| 13748 | * |
| 13749 | * @return Integer array of reasons for disallowing satellite communication. |
| 13750 | * |
| 13751 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13752 | */ |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13753 | public @NonNull int[] getAttachRestrictionReasonsForCarrier( |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13754 | int subId) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13755 | enforceSatelliteCommunicationPermission("getAttachRestrictionReasonsForCarrier"); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13756 | final long identity = Binder.clearCallingIdentity(); |
| 13757 | try { |
| 13758 | Set<Integer> reasonSet = |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13759 | mSatelliteController.getAttachRestrictionReasonsForCarrier(subId); |
Hakjun Choi | cb39db9 | 2023-07-14 15:51:12 +0000 | [diff] [blame] | 13760 | return reasonSet.stream().mapToInt(i->i).toArray(); |
| 13761 | } finally { |
| 13762 | Binder.restoreCallingIdentity(identity); |
| 13763 | } |
| 13764 | } |
| 13765 | |
| 13766 | /** |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13767 | * Request to get the signal strength of the satellite connection. |
| 13768 | * |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13769 | * @param result Result receiver to get the error code of the request and the current signal |
| 13770 | * strength of the satellite connection. |
| 13771 | * |
| 13772 | * @throws SecurityException if the caller doesn't have required permission. |
| 13773 | */ |
| 13774 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13775 | public void requestNtnSignalStrength(@NonNull ResultReceiver result) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13776 | enforceSatelliteCommunicationPermission("requestNtnSignalStrength"); |
| 13777 | final long identity = Binder.clearCallingIdentity(); |
| 13778 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13779 | mSatelliteController.requestNtnSignalStrength(result); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13780 | } finally { |
| 13781 | Binder.restoreCallingIdentity(identity); |
| 13782 | } |
| 13783 | } |
| 13784 | |
| 13785 | /** |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13786 | * Registers for NTN signal strength changed from satellite modem. If the registration operation |
| 13787 | * is not successful, a {@link ServiceSpecificException} that contains |
| 13788 | * {@link SatelliteManager.SatelliteResult} will be thrown. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13789 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13790 | * @param callback The callback to handle the NTN signal strength changed event. If the |
| 13791 | * operation is successful, {@link NtnSignalStrengthCallback#onNtnSignalStrengthChanged( |
| 13792 | * NtnSignalStrength)} will return an instance of {@link NtnSignalStrength} with a value of |
| 13793 | * {@link NtnSignalStrength.NtnSignalStrengthLevel} when the signal strength of non-terrestrial |
| 13794 | * network has changed. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13795 | * |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13796 | * @throws SecurityException If the caller doesn't have the required permission. |
| 13797 | * @throws ServiceSpecificException If the callback registration operation fails. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13798 | */ |
| 13799 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13800 | public void registerForNtnSignalStrengthChanged( |
Hakjun Choi | 4c3668a | 2023-12-05 11:55:36 +0000 | [diff] [blame] | 13801 | @NonNull INtnSignalStrengthCallback callback) throws RemoteException { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13802 | enforceSatelliteCommunicationPermission("registerForNtnSignalStrengthChanged"); |
| 13803 | final long identity = Binder.clearCallingIdentity(); |
| 13804 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13805 | mSatelliteController.registerForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13806 | } finally { |
| 13807 | Binder.restoreCallingIdentity(identity); |
| 13808 | } |
| 13809 | } |
| 13810 | |
| 13811 | /** |
| 13812 | * Unregisters for NTN signal strength changed from satellite modem. |
| 13813 | * If callback was not registered before, the request will be ignored. |
| 13814 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13815 | * changed event. |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13816 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13817 | * {@link #registerForNtnSignalStrengthChanged(INtnSignalStrengthCallback)} |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13818 | * |
| 13819 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13820 | */ |
| 13821 | @Override |
| 13822 | public void unregisterForNtnSignalStrengthChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13823 | @NonNull INtnSignalStrengthCallback callback) { |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13824 | enforceSatelliteCommunicationPermission("unregisterForNtnSignalStrengthChanged"); |
| 13825 | final long identity = Binder.clearCallingIdentity(); |
| 13826 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13827 | mSatelliteController.unregisterForNtnSignalStrengthChanged(callback); |
Hakjun Choi | fa3e617 | 2023-09-22 03:56:34 +0000 | [diff] [blame] | 13828 | } finally { |
| 13829 | Binder.restoreCallingIdentity(identity); |
| 13830 | } |
| 13831 | } |
| 13832 | |
| 13833 | /** |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13834 | * Registers for satellite capabilities change event from the satellite service. |
| 13835 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13836 | * @param callback The callback to handle the satellite capabilities changed event. |
| 13837 | * |
| 13838 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13839 | * |
| 13840 | * @throws SecurityException if the caller doesn't have required permission. |
| 13841 | */ |
| 13842 | @Override |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13843 | @SatelliteManager.SatelliteResult public int registerForCapabilitiesChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13844 | @NonNull ISatelliteCapabilitiesCallback callback) { |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13845 | enforceSatelliteCommunicationPermission("registerForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13846 | final long identity = Binder.clearCallingIdentity(); |
| 13847 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13848 | return mSatelliteController.registerForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13849 | } finally { |
| 13850 | Binder.restoreCallingIdentity(identity); |
| 13851 | } |
| 13852 | } |
| 13853 | |
| 13854 | /** |
| 13855 | * Unregisters for satellite capabilities change event from the satellite service. |
| 13856 | * If callback was not registered before, the request will be ignored. |
| 13857 | * |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13858 | * @param callback The callback that was passed to. |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13859 | * {@link #registerForCapabilitiesChanged(ISatelliteCapabilitiesCallback)}. |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13860 | * |
| 13861 | * @throws SecurityException if the caller doesn't have required permission. |
| 13862 | */ |
| 13863 | @Override |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13864 | public void unregisterForCapabilitiesChanged( |
Hakjun Choi | 3c9303b | 2023-12-21 06:37:41 +0000 | [diff] [blame] | 13865 | @NonNull ISatelliteCapabilitiesCallback callback) { |
| 13866 | enforceSatelliteCommunicationPermission("unregisterForCapabilitiesChanged"); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13867 | final long identity = Binder.clearCallingIdentity(); |
| 13868 | try { |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13869 | mSatelliteController.unregisterForCapabilitiesChanged(callback); |
Hakjun Choi | 8d96a56 | 2023-10-26 15:01:40 +0000 | [diff] [blame] | 13870 | } finally { |
| 13871 | Binder.restoreCallingIdentity(identity); |
| 13872 | } |
| 13873 | } |
| 13874 | |
| 13875 | /** |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13876 | * Registers for the satellite supported state changed. |
| 13877 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13878 | * @param callback The callback to handle the satellite supported state changed event. |
| 13879 | * |
| 13880 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 13881 | * |
| 13882 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13883 | */ |
| 13884 | @Override |
| 13885 | @SatelliteManager.SatelliteResult public int registerForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13886 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13887 | enforceSatelliteCommunicationPermission("registerForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13888 | final long identity = Binder.clearCallingIdentity(); |
| 13889 | try { |
| 13890 | return mSatelliteController.registerForSatelliteSupportedStateChanged(callback); |
| 13891 | } finally { |
| 13892 | Binder.restoreCallingIdentity(identity); |
| 13893 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13894 | } |
| 13895 | |
| 13896 | /** |
| 13897 | * Unregisters for the satellite supported state changed. |
| 13898 | * If callback was not registered before, the request will be ignored. |
| 13899 | * |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13900 | * @param callback The callback that was passed to |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13901 | * {@link #registerForSatelliteSupportedStateChanged(ISatelliteSupportedStateCallback)}. |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13902 | * |
| 13903 | * @throws SecurityException if the caller doesn't have the required permission. |
| 13904 | */ |
| 13905 | @Override |
| 13906 | public void unregisterForSatelliteSupportedStateChanged( |
joonhunshin | 83da7cd | 2024-08-22 08:53:35 +0000 | [diff] [blame] | 13907 | @NonNull ISatelliteSupportedStateCallback callback) { |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13908 | enforceSatelliteCommunicationPermission("unregisterForSatelliteSupportedStateChanged"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13909 | final long identity = Binder.clearCallingIdentity(); |
| 13910 | try { |
| 13911 | mSatelliteController.unregisterForSatelliteSupportedStateChanged(callback); |
| 13912 | } finally { |
| 13913 | Binder.restoreCallingIdentity(identity); |
| 13914 | } |
Hakjun Choi | f92ac75 | 2024-03-18 19:34:29 +0000 | [diff] [blame] | 13915 | } |
| 13916 | |
| 13917 | /** |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13918 | * This API can be used by only CTS to update satellite vendor service package name. |
| 13919 | * |
| 13920 | * @param servicePackageName The package name of the satellite vendor service. |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13921 | * @param provisioned Whether satellite should be provisioned or not. |
| 13922 | * |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13923 | * @return {@code true} if the satellite vendor service is set successfully, |
| 13924 | * {@code false} otherwise. |
| 13925 | */ |
Hakjun Choi | c339324 | 2024-06-26 18:02:08 +0000 | [diff] [blame] | 13926 | public boolean setSatelliteServicePackageName(String servicePackageName, |
| 13927 | String provisioned) { |
| 13928 | Log.d(LOG_TAG, "setSatelliteServicePackageName - " + servicePackageName |
| 13929 | + ", provisioned=" + provisioned); |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13930 | TelephonyPermissions.enforceShellOnly( |
| 13931 | Binder.getCallingUid(), "setSatelliteServicePackageName"); |
| 13932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13933 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13934 | "setSatelliteServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13935 | final long identity = Binder.clearCallingIdentity(); |
| 13936 | try { |
| 13937 | return mSatelliteController.setSatelliteServicePackageName(servicePackageName, |
| 13938 | provisioned); |
| 13939 | } finally { |
| 13940 | Binder.restoreCallingIdentity(identity); |
| 13941 | } |
Thomas Nguyen | d34a5fc | 2023-03-23 21:07:03 -0700 | [diff] [blame] | 13942 | } |
| 13943 | |
| 13944 | /** |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13945 | * This API can be used by only CTS to update satellite gateway service package name. |
| 13946 | * |
| 13947 | * @param servicePackageName The package name of the satellite gateway service. |
| 13948 | * @return {@code true} if the satellite gateway service is set successfully, |
| 13949 | * {@code false} otherwise. |
| 13950 | */ |
| 13951 | public boolean setSatelliteGatewayServicePackageName(@Nullable String servicePackageName) { |
| 13952 | Log.d(LOG_TAG, "setSatelliteGatewayServicePackageName - " + servicePackageName); |
| 13953 | TelephonyPermissions.enforceShellOnly( |
| 13954 | Binder.getCallingUid(), "setSatelliteGatewayServicePackageName"); |
| 13955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13956 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 13957 | "setSatelliteGatewayServicePackageName"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13958 | final long identity = Binder.clearCallingIdentity(); |
| 13959 | try { |
| 13960 | return mSatelliteController.setSatelliteGatewayServicePackageName(servicePackageName); |
| 13961 | } finally { |
| 13962 | Binder.restoreCallingIdentity(identity); |
| 13963 | } |
Thomas Nguyen | 1854a5a | 2023-04-04 09:31:47 -0700 | [diff] [blame] | 13964 | } |
| 13965 | |
| 13966 | /** |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13967 | * This API can be used by only CTS to update satellite pointing UI app package and class names. |
| 13968 | * |
| 13969 | * @param packageName The package name of the satellite pointing UI app. |
| 13970 | * @param className The class name of the satellite pointing UI app. |
| 13971 | * @return {@code true} if the satellite pointing UI app package and class is set successfully, |
| 13972 | * {@code false} otherwise. |
| 13973 | */ |
| 13974 | public boolean setSatellitePointingUiClassName( |
| 13975 | @Nullable String packageName, @Nullable String className) { |
| 13976 | Log.d(LOG_TAG, "setSatellitePointingUiClassName: packageName=" + packageName |
| 13977 | + ", className=" + className); |
| 13978 | TelephonyPermissions.enforceShellOnly( |
| 13979 | Binder.getCallingUid(), "setSatellitePointingUiClassName"); |
| 13980 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 13981 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 13982 | "setSatellitePointingUiClassName"); |
| 13983 | final long identity = Binder.clearCallingIdentity(); |
| 13984 | try { |
| 13985 | return mSatelliteController.setSatellitePointingUiClassName(packageName, className); |
| 13986 | } finally { |
| 13987 | Binder.restoreCallingIdentity(identity); |
| 13988 | } |
Thomas Nguyen | 87dce73 | 2023-04-20 18:27:16 -0700 | [diff] [blame] | 13989 | } |
| 13990 | |
| 13991 | /** |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 13992 | * This API can be used by only CTS to update the timeout duration in milliseconds that |
| 13993 | * satellite should stay at listening mode to wait for the next incoming page before disabling |
| 13994 | * listening mode. |
| 13995 | * |
| 13996 | * @param timeoutMillis The timeout duration in millisecond. |
| 13997 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 13998 | */ |
| 13999 | public boolean setSatelliteListeningTimeoutDuration(long timeoutMillis) { |
| 14000 | Log.d(LOG_TAG, "setSatelliteListeningTimeoutDuration - " + timeoutMillis); |
| 14001 | TelephonyPermissions.enforceShellOnly( |
| 14002 | Binder.getCallingUid(), "setSatelliteListeningTimeoutDuration"); |
| 14003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14004 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14005 | "setSatelliteListeningTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14006 | final long identity = Binder.clearCallingIdentity(); |
| 14007 | try { |
| 14008 | return mSatelliteController.setSatelliteListeningTimeoutDuration(timeoutMillis); |
| 14009 | } finally { |
| 14010 | Binder.restoreCallingIdentity(identity); |
| 14011 | } |
Thomas Nguyen | f9a533c | 2023-04-06 20:48:41 -0700 | [diff] [blame] | 14012 | } |
| 14013 | |
| 14014 | /** |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14015 | * This API can be used by only CTS to control ingoring cellular service state event. |
| 14016 | * |
| 14017 | * @param enabled Whether to enable boolean config. |
| 14018 | * @return {@code true} if the value is set successfully, {@code false} otherwise. |
| 14019 | */ |
| 14020 | public boolean setSatelliteIgnoreCellularServiceState(boolean enabled) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14021 | Log.d(LOG_TAG, "setSatelliteIgnoreCellularServiceState - " + enabled); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14022 | TelephonyPermissions.enforceShellOnly( |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14023 | Binder.getCallingUid(), "setSatelliteIgnoreCellularServiceState"); |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14025 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14026 | "setSatelliteIgnoreCellularServiceState"); |
| 14027 | final long identity = Binder.clearCallingIdentity(); |
| 14028 | try { |
| 14029 | return mSatelliteController.setSatelliteIgnoreCellularServiceState(enabled); |
| 14030 | } finally { |
| 14031 | Binder.restoreCallingIdentity(identity); |
| 14032 | } |
joonhunshin | f46f0d6 | 2024-09-27 14:06:26 +0000 | [diff] [blame] | 14033 | } |
| 14034 | |
| 14035 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14036 | * This API can be used by only CTS to override the timeout durations used by the |
| 14037 | * DatagramController module. |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14038 | * |
| 14039 | * @param timeoutMillis The timeout duration in millisecond. |
| 14040 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14041 | */ |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14042 | public boolean setDatagramControllerTimeoutDuration( |
| 14043 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14044 | Log.d(LOG_TAG, "setDatagramControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14045 | + reset + ", timeoutMillis=" + timeoutMillis); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14046 | TelephonyPermissions.enforceShellOnly( |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14047 | Binder.getCallingUid(), "setDatagramControllerTimeoutDuration"); |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14049 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14050 | "setDatagramControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14051 | final long identity = Binder.clearCallingIdentity(); |
| 14052 | try { |
| 14053 | return mSatelliteController.setDatagramControllerTimeoutDuration( |
| 14054 | reset, timeoutType, timeoutMillis); |
| 14055 | } finally { |
| 14056 | Binder.restoreCallingIdentity(identity); |
| 14057 | } |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14058 | } |
| 14059 | |
| 14060 | /** |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14061 | * This API can be used by only CTS to override the boolean configs used by the |
| 14062 | * DatagramController module. |
| 14063 | * |
| 14064 | * @param enable Whether to enable or disable boolean config. |
| 14065 | * @return {@code true} if the boolean config is set successfully, {@code false} otherwise. |
| 14066 | */ |
| 14067 | public boolean setDatagramControllerBooleanConfig( |
| 14068 | boolean reset, int booleanType, boolean enable) { |
| 14069 | Log.d(LOG_TAG, "setDatagramControllerBooleanConfig: booleanType=" + booleanType |
| 14070 | + ", reset=" + reset + ", enable=" + enable); |
| 14071 | TelephonyPermissions.enforceShellOnly( |
| 14072 | Binder.getCallingUid(), "setDatagramControllerBooleanConfig"); |
| 14073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14074 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14075 | "ssetDatagramControllerBooleanConfig"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14076 | final long identity = Binder.clearCallingIdentity(); |
| 14077 | try { |
| 14078 | return mSatelliteController.setDatagramControllerBooleanConfig(reset, booleanType, |
| 14079 | enable); |
| 14080 | } finally { |
| 14081 | Binder.restoreCallingIdentity(identity); |
| 14082 | } |
Aishwarya Mallampati | 3f0ef9b | 2024-05-17 22:47:04 +0000 | [diff] [blame] | 14083 | } |
| 14084 | |
| 14085 | |
| 14086 | /** |
Thomas Nguyen | 8b8777f | 2024-02-05 11:50:23 -0800 | [diff] [blame] | 14087 | * This API can be used by only CTS to override the timeout durations used by the |
| 14088 | * SatelliteController module. |
| 14089 | * |
| 14090 | * @param timeoutMillis The timeout duration in millisecond. |
| 14091 | * @return {@code true} if the timeout duration is set successfully, {@code false} otherwise. |
| 14092 | */ |
| 14093 | public boolean setSatelliteControllerTimeoutDuration( |
| 14094 | boolean reset, int timeoutType, long timeoutMillis) { |
| 14095 | Log.d(LOG_TAG, "setSatelliteControllerTimeoutDuration - " + timeoutMillis + ", reset=" |
| 14096 | + reset + ", timeoutMillis=" + timeoutMillis); |
| 14097 | TelephonyPermissions.enforceShellOnly( |
| 14098 | Binder.getCallingUid(), "setSatelliteControllerTimeoutDuration"); |
| 14099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14100 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14101 | "setSatelliteControllerTimeoutDuration"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14102 | final long identity = Binder.clearCallingIdentity(); |
| 14103 | try { |
| 14104 | return mSatelliteController.setSatelliteControllerTimeoutDuration( |
| 14105 | reset, timeoutType, timeoutMillis); |
| 14106 | } finally { |
| 14107 | Binder.restoreCallingIdentity(identity); |
| 14108 | } |
Hakjun Choi | ae36597 | 2023-04-25 11:00:31 +0000 | [diff] [blame] | 14109 | } |
| 14110 | |
| 14111 | /** |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14112 | * This API can be used in only testing to override connectivity status in monitoring emergency |
| 14113 | * calls and sending EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer. |
| 14114 | * |
| 14115 | * @param handoverType The type of handover from emergency call to satellite messaging. Use one |
| 14116 | * of the following values to enable the override: |
| 14117 | * 0 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_SOS |
| 14118 | * 1 - EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911 |
| 14119 | * To disable the override, use -1 for handoverType. |
| 14120 | * @param delaySeconds The event EVENT_DISPLAY_EMERGENCY_MESSAGE will be sent to Dialer |
| 14121 | * delaySeconds after the emergency call starts. |
| 14122 | * @return {@code true} if the handover type is set successfully, {@code false} otherwise. |
| 14123 | */ |
| 14124 | public boolean setEmergencyCallToSatelliteHandoverType(int handoverType, int delaySeconds) { |
| 14125 | Log.d(LOG_TAG, "setEmergencyCallToSatelliteHandoverType - " + handoverType); |
| 14126 | TelephonyPermissions.enforceShellOnly( |
| 14127 | Binder.getCallingUid(), "setEmergencyCallToSatelliteHandoverType"); |
| 14128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14129 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14130 | "setEmergencyCallToSatelliteHandoverType"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14131 | final long identity = Binder.clearCallingIdentity(); |
| 14132 | try { |
| 14133 | return mSatelliteController.setEmergencyCallToSatelliteHandoverType( |
| 14134 | handoverType, delaySeconds); |
| 14135 | } finally { |
| 14136 | Binder.restoreCallingIdentity(identity); |
| 14137 | } |
Thomas Nguyen | 11a051f | 2023-10-25 10:14:55 -0700 | [diff] [blame] | 14138 | } |
| 14139 | |
| 14140 | /** |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14141 | * This API can be used in only testing to override oem-enabled satellite provision status. |
| 14142 | * |
| 14143 | * @param reset {@code true} mean the overriding status should not be used, {@code false} |
| 14144 | * otherwise. |
| 14145 | * @param isProvisioned The overriding provision status. |
| 14146 | * @return {@code true} if the provision status is set successfully, {@code false} otherwise. |
| 14147 | */ |
| 14148 | public boolean setOemEnabledSatelliteProvisionStatus(boolean reset, boolean isProvisioned) { |
| 14149 | Log.d(LOG_TAG, "setOemEnabledSatelliteProvisionStatus - reset=" + reset |
| 14150 | + ", isProvisioned=" + isProvisioned); |
| 14151 | TelephonyPermissions.enforceShellOnly( |
| 14152 | Binder.getCallingUid(), "setOemEnabledSatelliteProvisionStatus"); |
| 14153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14154 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14155 | "setOemEnabledSatelliteProvisionStatus"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14156 | final long identity = Binder.clearCallingIdentity(); |
| 14157 | try { |
| 14158 | return mSatelliteController.setOemEnabledSatelliteProvisionStatus(reset, isProvisioned); |
| 14159 | } finally { |
| 14160 | Binder.restoreCallingIdentity(identity); |
| 14161 | } |
Thomas Nguyen | 3d60274 | 2024-01-19 11:29:35 -0800 | [diff] [blame] | 14162 | } |
| 14163 | |
| 14164 | /** |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14165 | * This API should be used by only CTS tests to forcefully set telephony country codes. |
| 14166 | * |
| 14167 | * @return {@code true} if the country code is set successfully, {@code false} otherwise. |
| 14168 | */ |
| 14169 | public boolean setCountryCodes(boolean reset, List<String> currentNetworkCountryCodes, |
| 14170 | Map cachedNetworkCountryCodes, String locationCountryCode, |
| 14171 | long locationCountryCodeTimestampNanos) { |
| 14172 | Log.d(LOG_TAG, "setCountryCodes: currentNetworkCountryCodes=" |
| 14173 | + String.join(", ", currentNetworkCountryCodes) |
| 14174 | + ", locationCountryCode=" + locationCountryCode |
| 14175 | + ", locationCountryCodeTimestampNanos" + locationCountryCodeTimestampNanos |
| 14176 | + ", reset=" + reset + ", cachedNetworkCountryCodes=" |
| 14177 | + String.join(", ", cachedNetworkCountryCodes.keySet())); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14178 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCountryCodes"); |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14180 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, "setCountryCodes"); |
| 14181 | final long identity = Binder.clearCallingIdentity(); |
| 14182 | try { |
| 14183 | return TelephonyCountryDetector.getInstance(getDefaultPhone().getContext(), |
| 14184 | mFeatureFlags).setCountryCodes(reset, currentNetworkCountryCodes, |
| 14185 | cachedNetworkCountryCodes, locationCountryCode, |
| 14186 | locationCountryCodeTimestampNanos); |
| 14187 | } finally { |
| 14188 | Binder.restoreCallingIdentity(identity); |
| 14189 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14190 | } |
| 14191 | |
| 14192 | /** |
| 14193 | * This API should be used by only CTS tests to override the overlay configs of satellite |
| 14194 | * access controller. |
| 14195 | * |
| 14196 | * @param reset {@code true} mean the overridden configs should not be used, {@code false} |
| 14197 | * otherwise. |
| 14198 | * @return {@code true} if the overlay configs are set successfully, {@code false} otherwise. |
| 14199 | */ |
| 14200 | public boolean setSatelliteAccessControlOverlayConfigs(boolean reset, boolean isAllowed, |
| 14201 | String s2CellFile, long locationFreshDurationNanos, |
| 14202 | List<String> satelliteCountryCodes) { |
| 14203 | Log.d(LOG_TAG, "setSatelliteAccessControlOverlayConfigs: reset=" + reset |
| 14204 | + ", isAllowed" + isAllowed + ", s2CellFile=" + s2CellFile |
| 14205 | + ", locationFreshDurationNanos=" + locationFreshDurationNanos |
| 14206 | + ", satelliteCountryCodes=" + ((satelliteCountryCodes != null) |
| 14207 | ? String.join(", ", satelliteCountryCodes) : null)); |
| 14208 | TelephonyPermissions.enforceShellOnly( |
| 14209 | Binder.getCallingUid(), "setSatelliteAccessControlOverlayConfigs"); |
| 14210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14211 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14212 | "setSatelliteAccessControlOverlayConfigs"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14213 | final long identity = Binder.clearCallingIdentity(); |
| 14214 | try { |
| 14215 | return mSatelliteAccessController.setSatelliteAccessControlOverlayConfigs(reset, |
| 14216 | isAllowed, s2CellFile, locationFreshDurationNanos, satelliteCountryCodes); |
| 14217 | } finally { |
| 14218 | Binder.restoreCallingIdentity(identity); |
| 14219 | } |
Thomas Nguyen | 4f9c89e | 2023-12-18 10:51:57 -0800 | [diff] [blame] | 14220 | } |
| 14221 | |
| 14222 | /** |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14223 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14224 | * value : config_send_satellite_datagram_to_modem_in_demo_mode, which determines whether |
| 14225 | * outgoing satellite datagrams should be sent to modem in demo mode. |
| 14226 | * |
| 14227 | * @param shouldSendToModemInDemoMode Whether send datagram in demo mode should be sent to |
| 14228 | * satellite modem or not. |
| 14229 | * |
| 14230 | * @return {@code true} if the operation is successful, {@code false} otherwise. |
| 14231 | */ |
| 14232 | public boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode) { |
| 14233 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14234 | Log.d(LOG_TAG, "shouldSendDatagramToModemInDemoMode: oemEnabledSatelliteFlag is " |
| 14235 | + "disabled"); |
| 14236 | return false; |
| 14237 | } |
| 14238 | Log.d(LOG_TAG, "setShouldSendDatagramToModemInDemoMode"); |
| 14239 | TelephonyPermissions.enforceShellOnly( |
| 14240 | Binder.getCallingUid(), "setShouldSendDatagramToModemInDemoMode"); |
| 14241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14242 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14243 | "setShouldSendDatagramToModemInDemoMode"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14244 | final long identity = Binder.clearCallingIdentity(); |
| 14245 | try { |
| 14246 | return mSatelliteController.setShouldSendDatagramToModemInDemoMode( |
| 14247 | shouldSendToModemInDemoMode); |
| 14248 | } finally { |
| 14249 | Binder.restoreCallingIdentity(identity); |
| 14250 | } |
Hakjun Choi | bc6ce99 | 2023-11-07 16:04:33 +0000 | [diff] [blame] | 14251 | } |
| 14252 | |
| 14253 | /** |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14254 | * This API can be used by only CTS to set the cache whether satellite communication is allowed. |
| 14255 | * |
| 14256 | * @param state a state indicates whether satellite access allowed state should be cached and |
| 14257 | * the allowed state. |
| 14258 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14259 | */ |
| 14260 | public boolean setIsSatelliteCommunicationAllowedForCurrentLocationCache(String state) { |
| 14261 | if (!mFeatureFlags.oemEnabledSatelliteFlag()) { |
| 14262 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14263 | + "oemEnabledSatelliteFlag is disabled"); |
| 14264 | return false; |
| 14265 | } |
| 14266 | |
| 14267 | Log.d(LOG_TAG, "setIsSatelliteCommunicationAllowedForCurrentLocationCache: " |
| 14268 | + "state=" + state); |
| 14269 | TelephonyPermissions.enforceShellOnly( |
| 14270 | Binder.getCallingUid(), |
| 14271 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
| 14272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14273 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14274 | "setIsSatelliteCommunicationAllowedForCurrentLocationCache"); |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14275 | final long identity = Binder.clearCallingIdentity(); |
| 14276 | try { |
| 14277 | return mSatelliteAccessController |
| 14278 | .setIsSatelliteCommunicationAllowedForCurrentLocationCache(state); |
| 14279 | } finally { |
| 14280 | Binder.restoreCallingIdentity(identity); |
| 14281 | } |
Hakjun Choi | 4a832d1 | 2024-05-28 22:23:55 +0000 | [diff] [blame] | 14282 | } |
| 14283 | |
| 14284 | /** |
Hunsuk Choi | 13078be | 2023-09-13 10:55:21 +0000 | [diff] [blame] | 14285 | * Sets the service defined in ComponentName to be bound. |
| 14286 | * |
| 14287 | * This should only be used for testing. |
| 14288 | * @return {@code true} if the DomainSelectionService to bind to was set, |
| 14289 | * {@code false} otherwise. |
| 14290 | */ |
| 14291 | @Override |
| 14292 | public boolean setDomainSelectionServiceOverride(ComponentName componentName) { |
| 14293 | Log.i(LOG_TAG, "setDomainSelectionServiceOverride component=" + componentName); |
| 14294 | |
| 14295 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14296 | "setDomainSelectionServiceOverride"); |
| 14297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14298 | getDefaultSubscription(), "setDomainSelectionServiceOverride"); |
| 14299 | |
| 14300 | final long identity = Binder.clearCallingIdentity(); |
| 14301 | try { |
| 14302 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14303 | return DomainSelectionResolver.getInstance() |
| 14304 | .setDomainSelectionServiceOverride(componentName); |
| 14305 | } |
| 14306 | } finally { |
| 14307 | Binder.restoreCallingIdentity(identity); |
| 14308 | } |
| 14309 | return false; |
| 14310 | } |
| 14311 | |
| 14312 | /** |
| 14313 | * Clears the DomainSelectionService override. |
| 14314 | * |
| 14315 | * This should only be used for testing. |
| 14316 | * @return {@code true} if the DomainSelectionService override was cleared, |
| 14317 | * {@code false} otherwise. |
| 14318 | */ |
| 14319 | @Override |
| 14320 | public boolean clearDomainSelectionServiceOverride() { |
| 14321 | Log.i(LOG_TAG, "clearDomainSelectionServiceOverride"); |
| 14322 | |
| 14323 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 14324 | "clearDomainSelectionServiceOverride"); |
| 14325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14326 | getDefaultSubscription(), "clearDomainSelectionServiceOverride"); |
| 14327 | |
| 14328 | final long identity = Binder.clearCallingIdentity(); |
| 14329 | try { |
| 14330 | if (DomainSelectionResolver.getInstance().isDomainSelectionSupported()) { |
| 14331 | return DomainSelectionResolver.getInstance() |
| 14332 | .clearDomainSelectionServiceOverride(); |
| 14333 | } |
| 14334 | } finally { |
| 14335 | Binder.restoreCallingIdentity(identity); |
| 14336 | } |
| 14337 | return false; |
| 14338 | } |
| 14339 | |
| 14340 | /** |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14341 | * Enable or disable notifications sent for cellular identifier disclosure events. |
| 14342 | * |
| 14343 | * Disclosure events are defined as instances where a device has sent a cellular identifier |
| 14344 | * on the Non-access stratum (NAS) before a security context is established. As a result the |
| 14345 | * identifier is sent in the clear, which has privacy implications for the user. |
| 14346 | * |
| 14347 | * @param enable if notifications about disclosure events should be enabled |
| 14348 | * @throws SecurityException if the caller does not have the required privileges |
| 14349 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14350 | */ |
| 14351 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14352 | public void setEnableCellularIdentifierDisclosureNotifications(boolean enable) { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14353 | enforceModifyPermission(); |
| 14354 | checkForIdentifierDisclosureNotificationSupport(); |
| 14355 | |
| 14356 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14357 | editor.putBoolean(Phone.PREF_IDENTIFIER_DISCLOSURE_NOTIFICATIONS_ENABLED, enable); |
| 14358 | editor.apply(); |
| 14359 | |
| 14360 | // Each phone instance is responsible for updating its respective modem immediately |
| 14361 | // after we've made a preference change. |
| 14362 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14363 | phone.handleIdentifierDisclosureNotificationPreferenceChange(); |
| 14364 | } |
| 14365 | } |
| 14366 | |
| 14367 | /** |
| 14368 | * Get whether or not cellular identifier disclosure notifications are enabled. |
| 14369 | * |
| 14370 | * @throws SecurityException if the caller does not have the required privileges |
| 14371 | * @throws UnsupportedOperationException if the modem does not support this feature. |
| 14372 | */ |
| 14373 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
Gil Cukierman | ff9ec8e | 2023-12-13 15:42:56 +0000 | [diff] [blame] | 14374 | public boolean isCellularIdentifierDisclosureNotificationsEnabled() { |
Gil Cukierman | 06403e1 | 2023-11-29 16:33:03 +0000 | [diff] [blame] | 14375 | enforceReadPrivilegedPermission("isCellularIdentifierDisclosureNotificationEnabled"); |
| 14376 | checkForIdentifierDisclosureNotificationSupport(); |
| 14377 | return getDefaultPhone().getIdentifierDisclosureNotificationsPreferenceEnabled(); |
| 14378 | } |
| 14379 | |
| 14380 | /** |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14381 | * Enables or disables notifications sent when cellular null cipher or integrity algorithms |
| 14382 | * are in use by the cellular modem. |
| 14383 | * |
| 14384 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14385 | * @throws SecurityException if the caller does not have the required privileges |
| 14386 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14387 | * and integrity algorithms in use |
| 14388 | * @hide |
| 14389 | */ |
| 14390 | @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) |
Michael Groover | ae447b2 | 2024-01-24 22:35:46 -0600 | [diff] [blame] | 14391 | public void setNullCipherNotificationsEnabled(boolean enable) { |
Michael Groover | 826b71d | 2023-12-21 22:08:06 -0600 | [diff] [blame] | 14392 | enforceModifyPermission(); |
| 14393 | checkForNullCipherNotificationSupport(); |
| 14394 | |
| 14395 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 14396 | editor.putBoolean(Phone.PREF_NULL_CIPHER_NOTIFICATIONS_ENABLED, enable); |
| 14397 | editor.apply(); |
| 14398 | |
| 14399 | // Each phone instance is responsible for updating its respective modem immediately |
| 14400 | // after a preference change. |
| 14401 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14402 | phone.handleNullCipherNotificationPreferenceChanged(); |
| 14403 | } |
| 14404 | } |
| 14405 | |
| 14406 | /** |
| 14407 | * Get whether notifications are enabled for null cipher or integrity algorithms in use by the |
| 14408 | * cellular modem. |
| 14409 | * |
| 14410 | * @throws IllegalStateException if the Telephony process is not currently available |
| 14411 | * @throws SecurityException if the caller does not have the required privileges |
| 14412 | * @throws UnsupportedOperationException if the modem does not support reporting on ciphering |
| 14413 | * and integrity algorithms in use |
| 14414 | * @hide |
| 14415 | */ |
| 14416 | @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) |
| 14417 | public boolean isNullCipherNotificationsEnabled() { |
| 14418 | enforceReadPrivilegedPermission("isNullCipherNotificationsEnabled"); |
| 14419 | checkForNullCipherNotificationSupport(); |
| 14420 | return getDefaultPhone().getNullCipherNotificationsPreferenceEnabled(); |
| 14421 | } |
| 14422 | |
| 14423 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 14424 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 14425 | * |
| 14426 | * <p>This method behaves in one of the following ways: |
| 14427 | * <ul> |
| 14428 | * <li>return true : if the calling package has the appop permission {@link |
| 14429 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 14430 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 14431 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 14432 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 14433 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 14434 | * </ul> |
| 14435 | */ |
| 14436 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 14437 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 14438 | for (Phone phone : PhoneFactory.getPhones()) { |
| 14439 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 14440 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 14441 | return true; |
| 14442 | } |
| 14443 | } |
| 14444 | return false; |
| 14445 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14446 | |
| 14447 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14448 | * @return The subscription manager service instance. |
| 14449 | */ |
| 14450 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 14451 | return SubscriptionManagerService.getInstance(); |
| 14452 | } |
| 14453 | |
| 14454 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14455 | * Class binds the consumer[callback] and carrierId. |
| 14456 | */ |
| 14457 | private static class CallerCallbackInfo { |
| 14458 | private final Consumer<Integer> mConsumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14459 | private final Set<Integer> mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14460 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14461 | public CallerCallbackInfo(Consumer<Integer> consumer, Set<Integer> carrierIds) { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14462 | mConsumer = consumer; |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14463 | mCarrierIds = carrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14464 | } |
| 14465 | |
| 14466 | public Consumer<Integer> getConsumer() { |
| 14467 | return mConsumer; |
| 14468 | } |
| 14469 | |
Steve Statia | 28b7cb3 | 2024-03-11 23:58:50 +0000 | [diff] [blame] | 14470 | public Set<Integer> getCarrierIds() { |
| 14471 | return mCarrierIds; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 14472 | } |
| 14473 | } |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14474 | |
| 14475 | /* |
| 14476 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14477 | * But the context that is passed in is unused if the phone app is already alive. |
| 14478 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14479 | */ |
| 14480 | @VisibleForTesting |
| 14481 | public void setPackageManager(PackageManager packageManager) { |
| 14482 | mPackageManager = packageManager; |
| 14483 | } |
| 14484 | |
| 14485 | /* |
Nate Myren | 453c347 | 2024-03-13 11:28:11 -0700 | [diff] [blame] | 14486 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with context. |
| 14487 | * But the context that is passed in is unused if the phone app is already alive. |
| 14488 | * In this case PackageManager object is different in PhoneInterfaceManager and Unit test. |
| 14489 | */ |
| 14490 | @VisibleForTesting |
| 14491 | public void setAppOpsManager(AppOpsManager appOps) { |
| 14492 | mAppOps = appOps; |
| 14493 | } |
| 14494 | |
| 14495 | /* |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14496 | * PhoneInterfaceManager is a singleton. Unit test calls the init() with FeatureFlags. |
| 14497 | * But the FeatureFlags that is passed in is unused if the phone app is already alive. |
| 14498 | * In this case FeatureFlags object is different in PhoneInterfaceManager and Unit test. |
| 14499 | */ |
| 14500 | @VisibleForTesting |
| 14501 | public void setFeatureFlags(FeatureFlags featureFlags) { |
| 14502 | mFeatureFlags = featureFlags; |
| 14503 | } |
| 14504 | |
| 14505 | /** |
| 14506 | * Make sure the device has required telephony feature |
| 14507 | * |
| 14508 | * @throws UnsupportedOperationException if the device does not have required telephony feature |
| 14509 | */ |
| 14510 | private void enforceTelephonyFeatureWithException(@Nullable String callingPackage, |
| 14511 | @NonNull String telephonyFeature, @NonNull String methodName) { |
| 14512 | if (callingPackage == null || mPackageManager == null) { |
| 14513 | return; |
| 14514 | } |
| 14515 | |
| 14516 | if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis() |
| 14517 | || !CompatChanges.isChangeEnabled(ENABLE_FEATURE_MAPPING, callingPackage, |
joonhunshin | f624b2a | 2024-04-18 04:42:12 +0000 | [diff] [blame] | 14518 | Binder.getCallingUserHandle()) |
| 14519 | || mVendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
| 14520 | // Skip to check associated telephony feature, |
| 14521 | // if compatibility change is not enabled for the current process or |
| 14522 | // the SDK version of vendor partition is less than Android V. |
joonhunshin | 4ac6094 | 2023-11-15 15:23:39 +0000 | [diff] [blame] | 14523 | return; |
| 14524 | } |
| 14525 | |
| 14526 | if (!mPackageManager.hasSystemFeature(telephonyFeature)) { |
| 14527 | throw new UnsupportedOperationException( |
| 14528 | methodName + " is unsupported without " + telephonyFeature); |
| 14529 | } |
| 14530 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14531 | |
| 14532 | /** |
| 14533 | * Registers for the satellite communication allowed state changed. |
| 14534 | * |
| 14535 | * @param subId The subId of the subscription to register for the satellite communication |
| 14536 | * allowed state changed. |
| 14537 | * @param callback The callback to handle the satellite communication allowed |
| 14538 | * state changed event. |
| 14539 | * |
| 14540 | * @return The {@link SatelliteManager.SatelliteResult} result of the operation. |
| 14541 | * |
| 14542 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14543 | */ |
| 14544 | @Override |
| 14545 | @SatelliteManager.SatelliteResult public int registerForCommunicationAllowedStateChanged( |
| 14546 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14547 | enforceSatelliteCommunicationPermission("registerForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14548 | final long identity = Binder.clearCallingIdentity(); |
| 14549 | try { |
| 14550 | return mSatelliteAccessController.registerForCommunicationAllowedStateChanged( |
| 14551 | subId, callback); |
| 14552 | } finally { |
| 14553 | Binder.restoreCallingIdentity(identity); |
| 14554 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14555 | } |
| 14556 | |
| 14557 | /** |
| 14558 | * Unregisters for the satellite communication allowed state changed. |
| 14559 | * If callback was not registered before, the request will be ignored. |
| 14560 | * |
| 14561 | * @param subId The subId of the subscription to unregister for the satellite communication |
| 14562 | * allowed state changed. |
| 14563 | * @param callback The callback that was passed to |
| 14564 | * {@link #registerForCommunicationAllowedStateChanged(int, |
| 14565 | * ISatelliteCommunicationAllowedStateCallback)}. * |
| 14566 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14567 | */ |
| 14568 | @Override |
| 14569 | public void unregisterForCommunicationAllowedStateChanged( |
| 14570 | int subId, @NonNull ISatelliteCommunicationAllowedStateCallback callback) { |
| 14571 | enforceSatelliteCommunicationPermission("unregisterForCommunicationAllowedStateChanged"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14572 | final long identity = Binder.clearCallingIdentity(); |
| 14573 | try { |
| 14574 | mSatelliteAccessController.unregisterForCommunicationAllowedStateChanged(subId, |
| 14575 | callback); |
| 14576 | } finally { |
| 14577 | Binder.restoreCallingIdentity(identity); |
| 14578 | } |
youngtaecha | 5d483d5 | 2024-04-29 17:05:45 +0000 | [diff] [blame] | 14579 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14580 | |
| 14581 | /** |
| 14582 | * Request to get the {@link SatelliteSessionStats} of the satellite service. |
| 14583 | * |
| 14584 | * @param subId The subId of the subscription to the satellite session stats for. |
| 14585 | * @param result The result receiver that returns the {@link SatelliteSessionStats} |
| 14586 | * if the request is successful or an error code if the request failed. |
| 14587 | * |
| 14588 | * @throws SecurityException if the caller doesn't have required permission. |
| 14589 | */ |
| 14590 | @Override |
| 14591 | public void requestSatelliteSessionStats(int subId, @NonNull ResultReceiver result) { |
| 14592 | enforceModifyPermission(); |
| 14593 | enforcePackageUsageStatsPermission("requestSatelliteSessionStats"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14594 | final long identity = Binder.clearCallingIdentity(); |
| 14595 | try { |
| 14596 | mSatelliteController.requestSatelliteSessionStats(subId, result); |
| 14597 | } finally { |
| 14598 | Binder.restoreCallingIdentity(identity); |
| 14599 | } |
Aishwarya Mallampati | f265cea | 2024-06-04 19:55:41 +0000 | [diff] [blame] | 14600 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14601 | |
| 14602 | /** |
| 14603 | * Request to get list of prioritized satellite subscriber ids to be used for provision. |
| 14604 | * |
| 14605 | * @param result The result receiver, which returns the list of prioritized satellite tokens |
| 14606 | * to be used for provision if the request is successful or an error code if the request failed. |
| 14607 | * |
| 14608 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14609 | */ |
| 14610 | @Override |
Hyosun | 6dbe854 | 2024-08-15 02:52:48 +0000 | [diff] [blame] | 14611 | public void requestSatelliteSubscriberProvisionStatus(@NonNull ResultReceiver result) { |
| 14612 | enforceSatelliteCommunicationPermission("requestSatelliteSubscriberProvisionStatus"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14613 | final long identity = Binder.clearCallingIdentity(); |
| 14614 | try { |
| 14615 | mSatelliteController.requestSatelliteSubscriberProvisionStatus(result); |
| 14616 | } finally { |
| 14617 | Binder.restoreCallingIdentity(identity); |
| 14618 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14619 | } |
| 14620 | |
| 14621 | /** |
| 14622 | * Deliver the list of provisioned satellite subscriber ids. |
| 14623 | * |
| 14624 | * @param list List of provisioned satellite subscriber ids. |
| 14625 | * @param result The result receiver that returns whether deliver success or fail. |
| 14626 | * |
| 14627 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14628 | */ |
| 14629 | @Override |
Hyosun Kim | b11f3ea | 2024-08-07 23:35:59 +0000 | [diff] [blame] | 14630 | public void provisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14631 | @NonNull ResultReceiver result) { |
| 14632 | enforceSatelliteCommunicationPermission("provisionSatellite"); |
Hyosun Kim | 0ab6b93 | 2024-08-16 04:45:09 +0000 | [diff] [blame] | 14633 | final long identity = Binder.clearCallingIdentity(); |
| 14634 | try { |
| 14635 | mSatelliteController.provisionSatellite(list, result); |
| 14636 | } finally { |
| 14637 | Binder.restoreCallingIdentity(identity); |
| 14638 | } |
Hyosun Kim | 8bac3be | 2024-06-28 13:35:30 +0000 | [diff] [blame] | 14639 | } |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14640 | |
| 14641 | /** |
Hyosun Kim | 578cdcd | 2024-09-24 13:29:19 +0000 | [diff] [blame] | 14642 | * Deliver the list of deprovisioned satellite subscriber ids. |
| 14643 | * |
| 14644 | * @param list List of deprovisioned satellite subscriber ids. |
| 14645 | * @param result The result receiver that returns whether deliver success or fail. |
| 14646 | * |
| 14647 | * @throws SecurityException if the caller doesn't have the required permission. |
| 14648 | */ |
| 14649 | @Override |
| 14650 | public void deprovisionSatellite(@NonNull List<SatelliteSubscriberInfo> list, |
| 14651 | @NonNull ResultReceiver result) { |
| 14652 | enforceSatelliteCommunicationPermission("deprovisionSatellite"); |
| 14653 | final long identity = Binder.clearCallingIdentity(); |
| 14654 | try { |
| 14655 | mSatelliteController.deprovisionSatellite(list, result); |
| 14656 | } finally { |
| 14657 | Binder.restoreCallingIdentity(identity); |
| 14658 | } |
| 14659 | } |
| 14660 | |
| 14661 | /** |
Hyosun | d6aaf06 | 2024-08-23 23:02:10 +0000 | [diff] [blame] | 14662 | * This API can be used by only CTS to override the cached value for the device overlay config |
| 14663 | * value : |
| 14664 | * config_satellite_gateway_service_package and |
| 14665 | * config_satellite_carrier_roaming_esos_provisioned_class. |
| 14666 | * These values are set before sending an intent to broadcast there are any change to list of |
| 14667 | * subscriber informations. |
| 14668 | * |
| 14669 | * @param name the name is one of the following that constitute an intent. |
| 14670 | * Component package name, or component class name. |
| 14671 | * @return {@code true} if the setting is successful, {@code false} otherwise. |
| 14672 | */ |
| 14673 | @Override |
| 14674 | public boolean setSatelliteSubscriberIdListChangedIntentComponent(String name) { |
| 14675 | if (!mFeatureFlags.carrierRoamingNbIotNtn()) { |
| 14676 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent:" |
| 14677 | + " carrierRoamingNbIotNtn is disabled"); |
| 14678 | return false; |
| 14679 | } |
| 14680 | Log.d(LOG_TAG, "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14681 | TelephonyPermissions.enforceShellOnly( |
| 14682 | Binder.getCallingUid(), "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14683 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 14684 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 14685 | "setSatelliteSubscriberIdListChangedIntentComponent"); |
| 14686 | final long identity = Binder.clearCallingIdentity(); |
| 14687 | try { |
| 14688 | return mSatelliteController.setSatelliteSubscriberIdListChangedIntentComponent(name); |
| 14689 | } finally { |
| 14690 | Binder.restoreCallingIdentity(identity); |
| 14691 | } |
| 14692 | } |
Jack Yu | 2673529 | 2024-09-25 14:33:49 -0700 | [diff] [blame] | 14693 | |
| 14694 | /** |
| 14695 | * This API can be used by only CTS to override the Euicc UI component. |
| 14696 | * |
| 14697 | * @param componentName ui component to be launched for testing. {@code null} to reset. |
| 14698 | * |
| 14699 | * @hide |
| 14700 | */ |
| 14701 | @Override |
| 14702 | public void setTestEuiccUiComponent(@Nullable ComponentName componentName) { |
| 14703 | enforceModifyPermission(); |
| 14704 | log("setTestEuiccUiComponent: " + componentName); |
| 14705 | mTestEuiccUiComponent = componentName; |
| 14706 | } |
| 14707 | |
| 14708 | /** |
| 14709 | * This API can be used by only CTS to retrieve the Euicc UI component. |
| 14710 | * |
| 14711 | * @return Euicc UI component. {@code null} if not available. |
| 14712 | * @hide |
| 14713 | */ |
| 14714 | @Override |
| 14715 | @Nullable |
| 14716 | public ComponentName getTestEuiccUiComponent() { |
| 14717 | enforceReadPrivilegedPermission("getTestEuiccUiComponent"); |
| 14718 | return mTestEuiccUiComponent; |
| 14719 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14720 | |
| 14721 | /** |
| 14722 | * This API can be used only for test purpose to override the carrier roaming Ntn eligibility |
| 14723 | * |
| 14724 | * @param state to update Ntn Eligibility. |
| 14725 | * @param resetRequired to reset the overridden flag in satellite controller. |
| 14726 | * @return {@code true} if the shell command is successful, {@code false} otherwise. |
| 14727 | */ |
| 14728 | public boolean overrideCarrierRoamingNtnEligibilityChanged(boolean state, |
| 14729 | boolean resetRequired) { |
Hyosun | 322782b | 2024-10-24 11:37:59 +0000 | [diff] [blame] | 14730 | final long identity = Binder.clearCallingIdentity(); |
| 14731 | try { |
| 14732 | return mSatelliteAccessController.overrideCarrierRoamingNtnEligibilityChanged(state, |
| 14733 | resetRequired); |
| 14734 | } finally { |
| 14735 | Binder.restoreCallingIdentity(identity); |
| 14736 | } |
arunvoddu | e3a6dbc | 2024-09-27 16:27:08 +0000 | [diff] [blame] | 14737 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 14738 | } |